Home >Web Front-end >JS Tutorial >js gets mouse position chat with multi-browser compatibility code_javascript skills

js gets mouse position chat with multi-browser compatibility code_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:58:17960browse

In fact, getting the mouse position is just a matter of one sentence, but if you don’t understand the differences between browsers, the whole process will be very frustrating. The difference is:
1. Use event to get the distance between the x and y axes under IE. .x and event.y;
To obtain the distance between the x and y axes under FF, use event.pageX and event.pageY respectively;
2.The position obtained by this method under IE is not counted as scrolled by the scroll bar. position, that is, it will only count to the edge of the browser;
FF will count the positions scrolled past;
(This place makes me collapse, for such a small difference, I put all the programs I use Rewritten everything, embarrassing...)
The solution to 1 is just to judge the browser and then use what method;
The solution to 2 is to use IE on the x and y axes Add document.documentElement.scrollTop and document.documentElement.scrollLeft respectively;
I know little about JS. If you have better suggestions, please leave a message! Thank you


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