user2066217
user2066217

Reputation: 11

Know the position of the mouse for the event onmousemove in IE 9, firefox and Chrome

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

Answers (1)

Matt
Matt

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

Related Questions