使用CSS,这是JQuery中的顶级属性 [英] Working with CSS, top propery in JQuery
本文介绍了使用CSS,这是JQuery中的顶级属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在100毫秒后更改bbb类的顶部位置,但结果发现.css(top)不起作用.
I want to change top position of class bbb after 100 ms, but it took out that .css(top) does not work.
请帮助.
<!DOCTYPE html>
<html>
<head>
<script src="jquery-3.2.1.min.js"></script>
</head>
<body>
<div class="ddd"><div class='bbb'>Bobobo</div></div>
</body>
<script>
$(function myFunction() {
setInterval(alertFunc, 100);
});
function alertFunc() {
var b = $('.bbb').first();
b.css('top', 100 + 'px');
}
</script>
</html>
推荐答案
就像提到的@jhpratt一样.您需要将position:relative
添加到.bbb
类中.
Just like @jhpratt mentioned. You need to add position:relative
to the .bbb
class.
请参阅下文.
$(function myFunction() {
setTimeout(alertFunc, 500);
});
function alertFunc() {
var b = $('.bbb').first();
b.css('top', 100 + 'px');
}
.bbb {
position: relative;
border: 1px solid red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<div class="ddd">
<div class='bbb'>Bobobo</div>
</div>
这篇关于使用CSS,这是JQuery中的顶级属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文