我正在尝试使用 css sprites 制作动画(请告诉我我的方法是否正确),请检查以下 jquery 代码...
$(document).ready(function() {
setTimeout("boat()",20);
});
function boat(){
$("#boat").animate({right:"+=110%"},20000).css("background-position","0 0").animate({left:"+=110%"},20000).css("background-position","0 -68px")
setTimeout("boat()",20000);
}
CSS:
#boat {
margin-top:160px;
position:absolute;
margin-left:100%;
width:150px;
height:68px;
background-image:url(plane.png);
background-repeat:no-repeat;
}
动画效果完美(从右到左,从左到右),但有一个小问题,css sprite 没有按预期工作。它只占用这个属性.css("background-position","0 -68px")