var mouseTrack = (function() {
document.onmousemove = handleMouseMove;
function handleMouseMove(event) {
var dot, eventDoc, doc, body, pageX, pageY;
event = event || window.event; // IE-ism
// If pageX/Y aren't available and clientX/Y are,
// calculate pageX/Y - logic taken from jQuery.
// (This is to support old IE)
if (event.pageX == null && event.clientX != null) {
eventDoc = (event.target && event.target.ownerDocument) || document;
doc = eventDoc.documentElement;
body = eventDoc.body;
event.pageX = event.clientX +
(doc && doc.scrollLeft || body && body.scrollLeft || 0) -
(doc && doc.clientLeft || body && body.clientLeft || 0);
event.pageY = event.clientY +
(doc && doc.scrollTop || body && body.scrollTop || 0) -
(doc && doc.clientTop || body && body.clientTop || 0 );
}
console.log(event.pageX + ', ' + event.pageY);
// document.body.innerHTML += '<div style="position:absolute;width:3px;height:3px;background:red;right:'+(window.innerWidth-event.pageX)+'px;top:'+event.pageY+'px;"></div>'
}
});
mouseTrack();
(try this in your browser :) )
If you race the mouse on high sensitivity across the page, you'll only get a coordinate set of like 10-20. If you do it slowly, you'll accumulate hundreds or thousands of points.
How often does a browser (let's say, Chrome) poll for mouse location to fire the mousemove event and even better, where is the source I can look at for this?
It is not the browser that is causing this effect. The browser does not poll the mouse position at all, actually.
It is the scripting engines implementation that takes a certain execution time for each command, thus is only able to compare positions every so many microseconds. If a change is detected an event is raised.
It is impossible to name a specific time here in my eyes, since obviously the execution time of single commands depends on the specific hardware and load of the system you test on.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With