I've a <div>
with a background-image that will change the background 4 times with a delay of 300ms. I've tried with setTimeout which seems to work correct, but clearTimeout(t); when the mouse moves out fails because the backgrounds continue changing.
$(document).ready(function() {
$(".image").hover(function(){
var obj = $('.image');
$(this).css("background-position", "0 -90");
var t=setTimeout(function(){obj.css("background-position", "0 -180")}, 300);
var t=setTimeout(function(){obj.css("background-position", "0 -270")}, 600);
var t=setTimeout(function(){obj.css("background-position", "0 -360")}, 900);
}, function() {
$(this).css("background-position", "0 0");
clearTimeout(t);
});
});
I would like too to insert to the hover function a way to have a infinite loop until the mouse is released.
Sorry for my school English.
Thanks in advance!