Last active
December 27, 2015 00:18
-
-
Save WebInspectInc/7236209 to your computer and use it in GitHub Desktop.
Animation Delay with rAF
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function animate (callback, time, oldTime) { | |
var oldTime = oldTime || new Date().getTime(); | |
var now = new Date(); | |
if (new Date(oldTime + time) < now) { | |
callback(); | |
oldTime = now.getTime(); | |
} | |
requestAnimationFrame(function() { animate(callback, time, oldTime); }); | |
} | |
//useage: | |
//animate(animateMyThing, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To use this you probably also need the rAF polyfill: http://www.paulirish.com/2011/requestanimationframe-for-smart-animating/