I’m trying to implement a jQuery function with an infinite loop to animate a div. I can’t figure out how to do it. This is my code:
$(document).ready(function() {
$('#divers').animate({'margin-top':'90px'},6000).animate({'margin-top':'40px'},6000);
});
put the code that does the full animation into a function, then pass that function as the callback param to the last animation. Something like...
Using setInterval is the way to go. Too much recursion will just get you "Stack Overflow" :-) "Uncaught RangeError: Maximum call stack size exceeded"
You can also set the set interval function specifying which method to call at what interval
The
animate()
function has an option to take a function to call when the animation ends. You could just do the same call, and voila.use the
.animate()
callback to 'recall' your function:jsBin demo