我试图动画的背景位置的一些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();
})发布于 2012-11-18 18:18:50
来自文档
所有动画属性都应动画为单个数值,但如下所述除外;不完全支持简写CSS属性(例如字体、背景、边框)。
要像你所做的那样使backgroundPositionY动画化,在Chrome中你可以简单地动画所述的属性。由于火狐不支持backgroundPositionY,所以您可以为不支持CSS钩的浏览器应用CSS钩:
if (!('backgroundPositionY' in document.createElement('div').style)) {
$.cssHooks.backgroundPositionY = {
get: function(elem, computed, extra) {
return $.css(elem, 'backgroundPosition').split(' ')[1];
},
set: function(elem, value) {
elem.style.backgroundPosition = $.css(elem, 'backgroundPosition').split(' ')[0] + ' ' + value;
}
};
}
$(function() {
function animateGrid() {
$('.divimg').animate({
backgroundPositionY: 250
}, 500, function() {
$('.divimg').animate({
backgroundPositionY: 0
}, 500);
});
}
animateGrid();
});在Chrome,FF,IE9中进行测试。应该能在所有浏览器中工作。
https://stackoverflow.com/questions/13442897
复制相似问题