I've been working on an animation function that I want to run in a loop. So far, I've managed to get it to work for one iteration, but I'm struggling to figure out how to repeat the loop a specific number of times. Below is the code for my animation function. Can someone please help me figure out how to run this any number of times or even make it a never-ending loop?
<script type="text/javascript">
$(document).ready(function(){
var delay = 150;
var times = 4;
var i = 1;
doMove = function() {
if( i < times ){
$('#lip').removeClass('lip'+i);
$('#lip').addClass('lip'+(i+1));
} else if ( i == times ) {
$('#lip').removeClass('lip4');
$('#lip').addClass('lip1');
}
++i;
if( i >= times ) {
clearInterval( interval ) ;
}
}
var interval = setInterval ( "doMove()", delay );
});
</script>
Thank you so much for your help. I'm still new to jquery.