Home >Web Front-end >JS Tutorial >js gets mouse position chat with multi-browser compatibility code_javascript skills
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