Home  >  Article  >  Web Front-end  >  JavaScript function to obtain mouse coordinates (compatible with IE, FireFox, Chrome)_javascript skills

JavaScript function to obtain mouse coordinates (compatible with IE, FireFox, Chrome)_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:36:321090browse

Fortunately, everything is available on the Internet. I found a function with the best browser compatibility online. It has been tested to be compatible with IE, FireFox, and Chrome, and there is no scroll bar error problem. Save it for future use:)

Copy code The code is as follows:

function mousePos(e){
var x,y;
var e = e||window.event;
return {
x:e.clientX document.body.scrollLeft document.documentElement.scrollLeft,
y:e.clientY document.body.scrollTop document .documentElement.scrollTop
};
}

Note: This function is used in conjunction with the onmousemove event.
Function source: mouse follow prompt box by nunumick
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn