javascript RAF-polyfill.js

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 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
}

以上是关于javascript RAF-polyfill.js的主要内容,如果未能解决你的问题,请参考以下文章

javascript JavaScript isset()等效: - JavaScript

JavaScript 使用JavaScript更改CSS(JavaScript)

JavaScript之基础-1 JavaScript(概述基础语法)

前端基础-JavaScript的基本概述和语法

JavaScript

JavaScript