开发者

Pause auto-rotate on mouseover (jQuery)

开发者 https://www.devze.com 2022-12-28 18:02 出处:网络
I\'m using a content slider plugin that is nice but lacks one important feature: does not stop auto-rotating slides on mouseover.

I'm using a content slider plugin that is nice but lacks one important feature: does not stop auto-rotating slides on mouseover.

Here's the rele开发者_如何转开发vant part from the script:

var dotimer = function (x){
    if((opts.auto) == true) {
        if(timer != null) 
            clearInterval(timer);

        timer = setInterval(function() {
                $(opts.next).click();
                }, 3000);
    }
}

dotimer();

Full script can be previewed here

I want the rotation to pause on mouseover and resume on mouseout.

Thanks in advance for your help!


You need to set and clear the timer in the hover event:

var stopTimer() = function () {
    if (!timer) return;
    clearInterval(timer);
    timer = false;
};
$(something).hover(
    function() { stopTimer(); },
    function() { doTimer();   }
);


Try:

$(opts.slides).hover(function() {
  clearInterval(timer);
},
function() {
  dotimer();
});


Found a solution here: http://www.dlocc.com/articles/jflow-slider-auto-slider-with-pause-functionality/

Thanks anyway.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号