setinterval() and clearinterval() - when cleared, does not animate automatically

后端 未结 1 1822
温柔的废话
温柔的废话 2021-01-03 08:39

So I\'m trying to build an animating background image which will cycle through an array of images.

The idea is also that when you click any navigation element on th

相关标签:
1条回答
  • 2021-01-03 09:08

    This should do it for you.

    var IntID = setTimer();
    
    function setTimer(){
         i = setInterval(startSlider, 4000);
         return i;
    }
    
    function stopSlider() {
        clearInterval(IntID);
    }
    
    //Restart Timer
    // Option 1 make a restartSlider function and call it
    $("#home").click(restartSlider);
    function restartSlider(){
          IntID = setTimer();
    }
    
    //Option 2 create an anonymous function only for that click event.
    $("#home").click(function(){
         IntID = setTimer();
    });
    
    0 讨论(0)
提交回复
热议问题