相关疑难解决方法(0)

代码如何检测是否在动画帧内运行?

如果某个函数被传递到requestAnimationFrame(),该函数如何检测到它正在动画帧内被调用?

function someFunction() {
  if (/* What goes here? */) {
    console.log('Inside animation frame.')
  }
  else {
    console.log('Not inside animation frame.')
  }
}

// The following lines should not be modified for the answer.
someFunction() // logs "Not inside animation frame."
requestAnimationFrame(someFunction) // eventually logs "Inside animation frame."
Run Code Online (Sandbox Code Playgroud)

最后两行不应修改。我很想知道是否可以检测到这种情况,而不需要用户记住以两种不同的方式使用该功能。最终用户应该像平常一样使用该函数,而不知道我的函数检测到用例。

javascript requestanimationframe

5
推荐指数
1
解决办法
1125
查看次数

标签 统计

javascript ×1

requestanimationframe ×1