Wanting to learn
Wanting to learn

Reputation: 468

run jquery animation every 5 seconds

How can a get a jquery animation to run say every 5 seconds?

so for something like this.

$('.zoom_big').animate({opacity: 1},2000,functions()}{
          $('.zoom_big').animate({opacity: 0},2000);
 });

Upvotes: 0

Views: 3018

Answers (1)

Yotam Omer
Yotam Omer

Reputation: 15356

You can use javascript's setInterval():

var t = setInterval(function(){ // run the following function

    $('.zoom_big').animate({opacity: 1},2000,functions()}{
          $('.zoom_big').animate({opacity: 0},2000);
    });

},5000); // every 5000 milliseconds = 5 seconds

To stop it you can use clearInterval()

clearInterval(t);

Upvotes: 4

Related Questions