【发布时间】:2012-11-18 17:59:42
【问题描述】:
我正在尝试为某些 div 的背景位置设置动画,然后是一个回调动画。
我在这里缺少什么?
HTML:
<div>
<div class='divimg'></div>
<div class='divimg'></div>
<div class='divimg'></div>
</div>
CSS:
.divimg {
width:250px;
height:250px;
margin:20px;
float:left;
background-size: 500px 500px;
background-position: top center;
background-repeat: no repeat;
background-image: url(http://lorempixel.com/186/116/nature/1);
}
JavaScript:
$(function() {
function animateGrid() {
$('.divimg').animate(
{backgroundPosition:"bottom center"},
500, function() {
$('.divimg').animate(
{backgroundPosition:"top center"},
500)
}
);
}
animateGrid();
})
【问题讨论】:
-
已知 jQuery 不能正确地为复合/文本值属性设置动画,但可以解决。
-
在 Chrome 中,可以使用 this 之类的东西,对于 Firefox,您必须创建一个 CSS Hook。
-
我明白了,所以对于 jQuery 动画,坚持使用整数而不是文本值属性是一种更好的做法。无论如何更改值都会更容易 - 谢谢
标签: jquery jquery-animate background-position