I'm trying to make an animation (please tell me if my approach is correct) using css sprites, check the following jquery code ...
$(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;
}
Animation works fine (from right to left and from left to right), but there is a small problem, css sprite does not work as expected. His only take of this property.css("background-position","0 -68px")
source
share