Blame view

天文台pc/tianwentai-ui/node_modules/react-smooth/es6/setRafTimeout.js 583 Bytes
bc518174   王天杨   提交两个项目文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
  function safeRequestAnimationFrame(callback) {
    if (typeof requestAnimationFrame !== 'undefined') requestAnimationFrame(callback);
  }
  export default function setRafTimeout(callback) {
    var timeout = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
    var currTime = -1;
    var shouldUpdate = function shouldUpdate(now) {
      if (currTime < 0) {
        currTime = now;
      }
      if (now - currTime > timeout) {
        callback(now);
        currTime = -1;
      } else {
        safeRequestAnimationFrame(shouldUpdate);
      }
    };
    requestAnimationFrame(shouldUpdate);
  }