kenny kenny - 5 months ago 12
jQuery Question

Make jQuery animate loop

I know there are other and more preferred methods, but I'm trying to give a div img a bounce effect using jQuery.

I'm trying to loop

$('#downarrow').animate({bottom:'4px'});
$('#downarrow').animate({bottom:'0px'});


Any help would be awesome. Thanks!

Answer

One very simple solution:

function bounceUp(){
    $('#downarrow').animate({bottom:'4px'}, 1000, bounceDown);
}
function bounceDown(){
    $('#downarrow').animate({bottom:'0px'}, 1000, bounceUp);
}

bounceUp();

An example: https://jsfiddle.net/DerekL/nd8kf61s/