function animLoop( render, element ) { var running, lastFrame = +new Date; function loop( now ) { // stop the loop if render returned false if ( running !== false ) { requestAnimationFrame( loop, element ); running = render( now - lastFrame ); lastFrame = now; } } loop( lastFrame ); } // Move the element on the right at ~600px/s animLoop(function( deltaT ) { elem.style.left = ( left += 10 * deltaT / 16 ) + "px"; if ( left > 400 ) { return false; } });