/ Published in: jQuery
URL: http://jquerydemo.com/demo/animate-background-image.aspx
you can animate background image by changing CSS background position property using jQuery setInterval method
Expand |
Embed | Plain Text
(function($) { // #your-image is div with the image background var yourImage = $("#your-image"); yourImage.css('backgroundPosition', '0px' + ' ' + '0px'); window.setInterval(function() { yourImage.css("backgroundPosition", x + 'px' + ' ' + y + 'px'); y--; }, 80); })(jQuery);
Comments
Subscribe to comments
You need to login to post a comment.

Why not just use .animate()? jQuery's goal is "more for less".. let's stay aligned with that vision, my friend!
yourImage.animate({ "background-position-x" : x, "background-position-y" : y });