David
David

Reputation: 2232

clearInterval is not working

I have a div that is above something I want to showcase, and I have the setInterval working, but the clearInterval isn’t firing when it reaches 2 loops.

I have this:

window.setInterval(play_ani_clickthese, 3000);
var fade_count = 0;

function play_ani_clickthese() {
    $("#click_these").fadeIn(1000).delay(1000).fadeOut(1000);
    fade_count += parseInt('1');

    if(fade_count == 2) window.clearInterval(play_ani_clickthese);
}

But when the 'fade_count' reaches 2, it just keeps going.

Any pointers to what I'm doing wrong?

Upvotes: 2

Views: 5811

Answers (1)

Mrchief
Mrchief

Reputation: 76208

Use it like this:

var id = window.setInterval(play_ani_clickthese, 3000);
clearInterval(id);

Upvotes: 12

Related Questions