Copy, but the code of the original page still needs to be modified. The following is the available modifications
Commonly used is event.clientX and event.clientY to obtain horizontal and vertical positions respectively, but using this method alone is not enough because the mouse position obtained by event.clientX and event.clientY is relative to the current screen, regardless of the distance scrolling by the scroll bar of the page.
The code copy is as follows:
function pointerX(event)
{
return event.pageX || (event.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft));
}
function pointerY(event)
{
return event.pageY || (event.clientY + (document.documentElement.scrollTop || document.body.scrollTop));
}
The two methods respectively obtain the mouse position relative to the entire page (rather than the screen)
event.pageX is supported in FF, which implements cross-browser operations
Just call these two functions in other methods
The code copy is as follows:
function getPointPosition(event)
{
var x_px_scr = event.clientX;
var y_px_scr = event.clientY;
alert("X-axis offset relative to the current screen" + x_px_scr);<span style="font-family: tahoma, helvetica, arial;">//Relative to device (PC or mobile device)</span>
alert("Y-axis offset relative to the current screen" + y_px_scr);//Relative to device (PC or mobile device)
var x_Px_page = pointerX(event);
var y_Px_page = pointerY(event);
alert("X-axis offset relative to the entire page" + x_Px_page); //Relative to the browser
alert("Y-axis offset relative to the entire page" + y_Px_page); //Relative to the browser
}