收藏
回答

小游戏demorequestAnimationFrame传递了俩个参数,这是怎么

小游戏demorequestAnimationFrame传递了俩个参数,这是怎么回事,有知道的大佬说下呗

回答关注问题邀请回答
收藏

1 个回答

  • Stephen
    Stephen
    2018-12-05

    还有第三个参数呢,你知不知道,下面是部分源码


    var documentCreateElement = document.createElement.bind(document)
    var requestAnimationFrame = window.requestAnimationFrame.bind(window)
    var cancelAnimationFrame = window.cancelAnimationFrame.bind(window)
     
    var _fpsInterval, RAFIdMap = {}, cid = 0
     
    var wxRequestAnimationFrame = (cb, id, last) => {
      if (!_fpsInterval) return requestAnimationFrame(cb)
      if (!id) {
        id = cid++
      }
      if (!last) {
        last = +new Date()
        var nativeId = requestAnimationFrame(wxRequestAnimationFrame.bind(this, cb, id, last))
        RAFIdMap[id] = nativeId
        return id
      }
      var now = +new Date()
      if (now - last >= _fpsInterval) {
        last = now - (last % _fpsInterval)
        delete RAFIdMap[id]
        cb()
      } else {
        var nativeId = requestAnimationFrame(wxRequestAnimationFrame.bind(this, cb, id, last))
        RAFIdMap[id] = nativeId
        return id
      }
    }


    2018-12-05
    有用 1
    回复 1
    • 那些年
      那些年
      2018-12-05

      谢谢回复这么多,长见识了,这是官方自己增加的吧

      2018-12-05
      回复
登录 后发表内容