<script type="text/javascript" src="./Scripts/jquery-1.5.1.min.js"></script>
<script type='text/javascript' >
$(document).ready(function () {
$("#start").animate({ left: "+=10px" }, 1000)
.animate({ left: "-5000px" }, 1000);
});
</script>
<p id="start">this is some text that i am going to animate </p>
我正在绞尽脑汁地想知道为什么它没有动画。如果我将 left
更改为 marginLeft
它将按预期工作并显示动画。但我不确定为什么 left
不这样做。
谁能解释一下吗?我见过许多其他脚本在做类似的事情。
最佳答案
要使定位正常工作,您需要通过设置 position
css 属性来启用它。
将其设置为固定
或绝对
或相对
即可工作(取决于您想要实现的目标)
引用 position
MDC docs 的规范属性。
Initial value : static
和
static
Normal behavior. The top, right, bottom, and left properties do not apply.
关于jQuery animate({left :"+=10"}) 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5723230/