ali322
5/12/2018 - 8:10 AM

raf-polyfill.js

raf-polyfill.js

const vendors = ['webkit', 'moz']
for (let i = 0; i < vendors.length && !window.requestAnimationFrame; ++i) {
  const vp = vendors[i]
  window.requestAnimationFrame = window[vp + 'RequestAnimationFrame']
  window.cancelAnimationFrame =
    window[vp + 'CancelAnimationFrame'] ||
    window[vp + 'CancelRequestAnimationFrame']
}
if (
  /iP(ad|hone|od).*OS 6/.test(window.navigator.userAgent) || // iOS6 is buggy
  !window.requestAnimationFrame ||
  !window.cancelAnimationFrame
) {
  let lastTime = 0
  window.requestAnimationFrame = function(callback) {
    const now = Date.now()
    const nextTime = Math.max(lastTime + 16, now)
    return setTimeout(function() {
      callback((lastTime = nextTime))
    }, nextTime - now)
  }
  window.cancelAnimationFrame = clearTimeout
}