How does the triggering of mousemove work in Javascript?

I have an object that prints the mouse's x and y positions on every mousemove.

It's something like this:

$('#canvas').mousemove(function(e){
    $('#output').prepend(e.pageX + ',' + e.pageY);
});

I've noticed that when you move over the object really fast it only prints out a few positions.

I'm not exactly unhappy that it does that (because it would be quite exhaustive to have it do something for all the hundreds of pixels you've crossed) but I am wondering how this works.

Is the mousemove event limited to a certain amount of triggers per second or what?

(Btw: this was tested on Chromium in Ubuntu Linux)


“小鼠只能每秒n次向操作系统报告自己的位置,我认为n通常小于100”


You may want to look at this, as this may be browser dependent,

http://javascript.info/tutorial/mouse-events#mousemove-and-mouseover-frequency, but, if you look at this question, there is a suggestion on how to get better response.

How to set mousemove update speed?


i think it's synchronous. It's doesn't get triggered for every pixel in which you move your mouse, which means that the events are not queued up .

Say if you have some some code like this.

$('#canvas').mousemove(function(e){
//Some code which takes seconds to execute 
//All subsequent events won't be dispatched while this event handler is executing. 
});

Say if you move mouse while the mouse move event handlers execute. The mousemove handler won't be triggered.

Here is a example for handler which will take seconds to execute. --> http://jsfiddle.net/78Hf3/1/

And one that take only few time --> http://jsfiddle.net/78Hf3/2/

链接地址: http://www.djcxy.com/p/6916.html

上一篇: 是否有某种'断言'覆盖工具(用于Java)?

下一篇: 在Javascript中触发mousemove如何工作?