用javascript清除间隔

Mik*_*ind 0 javascript jquery intervals setinterval

我制作了一段间隔的动画.这是我的脚本:

var count = 0;
var countSecond = -40;
function arrowAnimation() {
    if (count > 40) {
        clearInterval();
    }
    $('.list-what-we-do .arrow').css({
        top: (count++) + 'px'
    });
}
function arrowAnimationSecond() {
    if (countSecond > 0) {
        clearInterval();
    }
    $('.list-what-we-do .arrow').css({
        right: (countSecond++) + 'px'
    });
}

setInterval(arrowAnimation, 5);
setInterval(arrowAnimationSecond, 5);
Run Code Online (Sandbox Code Playgroud)

现在我的问题.我怎么能停止间隔.我使用了clearInterval.但这不起作用.我怎样才能解决这个问题?谢谢你的帮助!

Gra*_*ham 5

当你使用setIntervalsetTimeout返回值是一个参考; 你把这个引用传递clearInterval给取消.

var foo = setTimeout(...);
clearTimeout(foo);
Run Code Online (Sandbox Code Playgroud)