Skip to content

Instantly share code, notes, and snippets.

@zerobias
Created April 8, 2019 04:58
Show Gist options
  • Save zerobias/9011bb30b5170b06f6c19e7ef6ab9c3c to your computer and use it in GitHub Desktop.
Save zerobias/9011bb30b5170b06f6c19e7ef6ab9c3c to your computer and use it in GitHub Desktop.
requestAnimationFrame
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