Created
April 8, 2019 04:58
-
-
Save zerobias/9011bb30b5170b06f6c19e7ef6ab9c3c 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
const root = function () { | |
if (typeof window !== 'undefined') return window | |
if (typeof self !== 'undefined') return self | |
if (typeof globalThis !== 'undefined') return globalThis | |
if (typeof global !== 'undefined') return global | |
if (typeof this !== 'undefined') return this | |
}() | |
export const requestAnimationFrame = | |
root.requestAnimationFrame || | |
root.webkitRequestAnimationFrame || | |
root.mozRequestAnimationFrame || | |
function requestAnimationFrame(cb) { | |
return setTimeout(cb, 1e3 / 60) | |
} | |
export const cancelAnimationFrame = | |
root.cancelAnimationFrame || | |
function cancelAnimationFrame(id) { | |
return clearTimeout(id) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment