Reputation: 11
I use this function to obtain the position of the mouse for the event onmousemove
, but get a different result in Internet Explorer 9.
function mouseCoords(ev){
if(ev.pageX || ev.pageY){
return {x:ev.pageX, y:ev.pageY};
}
return {
x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
y:ev.clientY + document.body.scrollTop - document.body.clientTop
};
}
What is the function for the majority of browsers?
Upvotes: 1
Views: 104
Reputation: 5428
The most consistent way to track the mouse coordinates across browsers is to use jQuery. http://docs.jquery.com/Tutorials:Mouse_Position
Upvotes: 1