如何设置mousemove更新速度? [英] How to set mousemove update speed?

查看:153
本文介绍了如何设置mousemove更新速度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在需要设置简单和快速签名的情况下生成一个函数。我正在画布领域写签名。我使用jQuery,但mousemove坐标的刷新速度不够快。发生什么事是,如果你写签名的速度很快,你会发现writed像素之间有一些空白。



如何设置mousemove的刷新速度更快?

  $(#xx)。mousemove(function(e){

ctx.fillRect(e .pageX - size,e.pageY - size,size,size);

$(#pagex)。html(e.pageX - size);
$(#pagey ).html(e.pageY - size);

}


解决方案

你不能,mousemove事件是由浏览器生成的,因此你可以像浏览器生成它们一样快速地接收它们。



浏览器没有义务以任何给定的速率生成事件(通过像素移动或时间流逝):如果快速移动鼠标,您将看到坐标中的跳转被报告为浏览器正在报告鼠标移动了,它现在就在这里,而不是......并通过这些像素。实际上,慢速计算机上的浏览器可能会减少鼠标移动事件,以免页面变慢。



你可以做的是用直线连接mousemove事件的连续位置 - 这显然不会让你更精准,但可以减轻影响。

im generating a function where it needs to set easy and fast a signature. I'm writing the signature in an canvas field. I use jQuery for it, but the refresh rate of mousemove coordinates is not fast enough. What happens is that if you write your signature to fast, you see some white spaces between writed pixels.

How can I set the refresh speed of the mousemove faster?

$("#xx").mousemove(function(e){

    ctx.fillRect(e.pageX - size, e.pageY - size, size, size);

    $("#pagex").html(e.pageX - size);
    $("#pagey").html(e.pageY - size);

}

解决方案

You can't. The mousemove events are generated by the browser, and thus you are receiving them as fast as the browser is generating them.

The browser is not obliged to generate the events at any given rate (either by pixels moved, or by time elapsed): if you move the mouse quickly, you will see that a "jump" in coordinates is reported, as the browser is reporting "the mouse has moved, and it is now here", not "...and went through these pixels". In fact, a browser on a slow computer might generate fewer mousemove events, lest the page slow down to a crawl.

What you could do is to connect successive positions from mousemove events with a straight line - this will obviously not get you any more precision, but it may mitigate the impact.

这篇关于如何设置mousemove更新速度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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