Last active
January 20, 2017 02:41
-
-
Save senola/3cc4115c6a0df90feff6acb00c5fdd34 to your computer and use it in GitHub Desktop.
requestAnimationFrame兼容写法
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.requestAnimationFrame = | |
| window.__requestAnimationFrame || | |
| window.requestAnimationFrame || | |
| window.webkitRequestAnimationFrame || | |
| window.mozRequestAnimationFrame || | |
| window.oRequestAnimationFrame || | |
| window.msRequestAnimationFrame || | |
| (function () { | |
| return function (callback, element) { | |
| var lastTime = element.__lastTime; | |
| if (lastTime === undefined) { | |
| lastTime = 0; | |
| } | |
| var currTime = Date.now(); | |
| var timeToCall = Math.max(1, 33 - (currTime - lastTime)); | |
| window.setTimeout(callback, timeToCall); | |
| element.__lastTime = currTime + timeToCall; | |
| }; | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment