V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
joe2016

适合响应交互的 requestAnimationFrame

  •  
  •   joe2016 · Jul 9, 2017 · 1296 views
    This topic created in 3217 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   ·   835 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 127ms · UTC 20:00 · PVG 04:00 · LAX 13:00 · JFK 16:00
    ♥ Do have faith in what you're doing.