문제

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); 

  });
도움이 되었습니까?

해결책

Try to use like this.

window.setTimeout(function(){
   clearInterval(loop);
}, 2000);

다른 팁

Use setTimeout() and clearInterval()

setTimeout(function(){
   clearInterval(loop);
},2000);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top