Created
April 22, 2016 09:36
-
-
Save zhoufenfens/85aba500200db3ea38125b8e5d71e59d to your computer and use it in GitHub Desktop.
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
window.requestAnimFrame = (function() { | |
return window.requestAnimationFrame || | |
window.webkitRequestAnimationFrame || | |
window.mozRequestAnimationFrame || | |
window.oRequestAnimationFrame || | |
window.msRequestAnimationFrame || | |
function(/* function */ callback, /* DOMElement */ element){ | |
window.setTimeout(callback, 1000 / 60); | |
}; | |
})(); | |
window.requestInterval = function(fn, delay) { | |
if( !window.requestAnimationFrame && | |
!window.webkitRequestAnimationFrame && | |
!(window.mozRequestAnimationFrame && window.mozCancelRequestAnimationFrame) && !window.oRequestAnimationFrame && | |
!window.msRequestAnimationFrame) | |
return window.setInterval(fn, delay); | |
var start = new Date().getTime(), | |
handle = new Object(); | |
function loop() { | |
var current = new Date().getTime(), | |
delta = current - start; | |
if(delta >= delay) { | |
fn.call(); | |
start = new Date().getTime(); | |
} | |
handle.value = requestAnimFrame(loop); | |
}; | |
handle.value = requestAnimFrame(loop); | |
return handle; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment