joe2016

适合响应交互的 requestAnimationFrame

  •  
  •   joe2016 · Jul 9, 2017 · 1375 views
    This topic created in 3257 days ago, the information mentioned may be changed or developed.

    发现 window.requestAnimationFrame 并不会管理队列。即在同一帧内多次调用window.requestAnimationFrame 会导致下一次重绘时,重复动画。例如:

    const animationTwice = () => console.log('I will be invoked twice!')
    
    // 在同一帧内调用两次,导致 animationTwice 执行两次
    window.requestAnimationFrame(animationTwice)
    window.requestAnimationFrame(animationTwice)
    // I will be invoked twice!
    // I will be invoked twice!
    

    所以,写了 raf-plus 库来管理 window.requestAnimationFrame 保证在同一帧内最多只会执行一次相同的动画函数。

    有不足之处,欢迎指正

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5215 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 05:44 · PVG 13:44 · LAX 22:44 · JFK 01:44
    ♥ Do have faith in what you're doing.