gpt4 book ai didi

javascript - mousemove 事件是否每帧触发一次?

转载 作者:行者123 更新时间:2023-11-30 09:33:34 25 4
gpt4 key购买 nike

在此fiddle demo , 按下并移动鼠标将根据鼠标的位置绘制点。 draw 方法是监听 mousemove 回调,但它绘制了离散点,表明 mousemove 事件没有连续触发。

此外,我收集了 event.timeStamp 并登录了控制台。我发现相邻事件之间的偏移量接近 16.7 毫秒。那么 mousemove 事件是否每帧触发一次?

最佳答案

mousemove 事件频率是特定于实现的,未由任何规范定义。

A user agent MUST dispatch this event when a pointing device is moved while it is over an element. The frequency rate of events while the pointing device is moved is implementation-, device-, and platform-specific, but multiple consecutive mousemove events SHOULD be fired for sustained pointer-device movement, rather than a single event for each instance of mouse movement. Implementations are encouraged to determine the optimal frequency rate to balance responsiveness with performance.

-- UI Events, W3C Working Draft, 04 August 2016

某些平台上的某些浏览器完全有可能将其限制为每帧一次。但是,不能保证任何可能执行此操作的浏览器都会继续执行此操作。

如果你想画一条连续的线,你需要在每两个点之间创建插值数据。

关于javascript - mousemove 事件是否每帧触发一次?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44898149/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com