Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)

like image 910
skerit Avatar asked May 11 '11 18:05

skerit


2 Answers

"Mice only report their position to the operating system n times per second, and I think n is usually less than 100"

like image 58
Mike Blandford Avatar answered Sep 20 '22 13:09

Mike Blandford


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?

like image 26
James Black Avatar answered Sep 21 '22 13:09

James Black