首页 > 解决方案 > 如何在鼠标悬停/悬停时暂停 setInterval() 函数?

问题描述

我无法找到暂停 setInterval() 的好解决方案。也许我以一种糟糕的方式建立了它,但我仍在学习。我想做的是在悬停/鼠标悬停时暂停 setInterval() 。我知道我将不得不以某种方式使用 clearInterval(),但我不知道如何。有人有任何提示吗?这就是我正在使用的:

    var divs = $('.section').toArray();
    function getsectionNext() {
        divs.push(divs.shift());
        return divs[0];}
    function sectionInterval() {
        setInterval(function() {
            $('.section').removeClass('active');
            $(getsectionNext()).addClass('active');
        },10000);}
    setInterval(sectionInterval());

非常感谢您为解决此问题提供的任何帮助!

标签: jqueryhoversetintervalmouseoverclearinterval

解决方案


推荐阅读