我的情况是这样开始的:我想对 div 的背景图像进行动画处理,但似乎使用 jquery 我无法检索背景图像的各个位置(背景位置)。所以我想为什么不创建一个对象并为其值设置动画,然后将这些值放入 css 中,但我还不知道如何完全做到这一点。这是我尝试过的。
var obj={t:0};
$("#wrapper").animate({
obj:100 //I tried obj.t & t as well
},1000,'linear',function(){},function(){
$("#wrapper").css({
'background-position':obj.t+"% 0%"
});
});
我还需要问的另一个问题是,如果图片真的很大,我的意思是大约 4000x4000px,将其设置为背景图像并更改背景位置,或者围绕 div 本身移动会更好吗?
您需要使用step功能 http://api.jquery.com/animate/#stepanimate 方法的,更重要的是你需要为实际对象设置动画......而不是#wrapper
element
var obj = {
t: 0
};
$(obj).animate({ // call animate on the object
t: 100 // specify the t property of the object to be animated
}, {
duration: 1000,
easing: 'linear',
step: function(now) { // called for each animation step (now refers to the value changed)
$("#wrapper").css({
'background-position': now + "% 0%"
});
}
});
Demo at http://jsfiddle.net/gaby/yPq8s/1/ http://jsfiddle.net/gaby/yPq8s/1/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)