Try to use like this.
window.setTimeout(function(){
clearInterval(loop);
}, 2000);
Question
How do I stop it after some time? For example 2 seconds. Thanks
$('img').mouseover(function() {
var image = this;
loop = setInterval(function() {
if (i < images.length - 1) {
i++;
$(image).attr('src',images[i]);
} else {
i = 0;
$(image).attr('src',images[i]);
}
}, 40);
});
Solution
Try to use like this.
window.setTimeout(function(){
clearInterval(loop);
}, 2000);
OTHER TIPS
Use setTimeout()
and clearInterval()
setTimeout(function(){
clearInterval(loop);
},2000);