var intervalID = setInterval(function(){ element.style.top = (i--<=100) ? i+'px' : i = 0; }, i); window.clearInterval(intervalID);