鼠标移动事件每帧触发一次吗? [英] Is mousemove event fire once in per frame?

查看:81
本文介绍了鼠标移动事件每帧触发一次吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此小提琴演示中,按并移动鼠标将根据鼠标的位置绘制点.位置.draw方法侦听 mousemove 回调,但是绘制离散点,该离散点表明 mousemove 事件未连续触发.

In this fiddle demo, press and move the mouse will draw the dot according to the mouse's position. The draw method is listen to mousemove callback, but it draw the discrete dot which show that the mousemove event is not fired continuously.

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

What is more, I collect the event.timeStamp and log in console. I found that the offset between adjacent event is near 16.7ms. So is mousemove event fire once in per frame?

推荐答案

mousemove 事件的频率是特定于实现的,没有任何规范定义.

The mousemove event frequency is implementation specific, and not defined by any specification.

当指针设备在元素上方移动时,用户代理必须调度此事件.指向设备移动时事件的发生频率是特定于实现,设备和平台的,但是应该触发多个连续的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事件,W3C工作草案,2016年8月4日

在某些平台上,某些浏览器完全有可能将其限制为每帧一次.但是,不能保证任何浏览器都可以继续这样做.

It's entirely possible some browsers on some platforms will limit it to once per-frame. There is no guarantee any browser that may do this will continue to do so however.

如果要绘制连续线,则需要在每两个点之间创建插值数据.

If you want to draw a continuous line, you would need to create interpolation data between each two points.

这篇关于鼠标移动事件每帧触发一次吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆