Js to get the mouse click on the location of the train of thought and code
- 2020-03-30 02:52:28
- OfStack
The copy is here, but the code of the original page still needs to be modified
Event.clientx and event.clienty are commonly used to get horizontal and vertical positions, respectively, but this method alone is not sufficient because event.clientx and event.clienty get the mouse position relative to the current screen, regardless of how far the page's scroll bar is scrolling.
Each method gets a mouse position relative to the entire page, not the screen
Event.pagex is supported in FF, which enables cross-browser operations
You simply call these two functions in other methods
Event.clientx and event.clienty are commonly used to get horizontal and vertical positions, respectively, but this method alone is not sufficient because event.clientx and event.clienty get the mouse position relative to the current screen, regardless of how far the page's scroll bar is scrolling.
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));
}
Each method gets a mouse position relative to the entire page, not the screen
Event.pagex is supported in FF, which enables cross-browser operations
You simply call these two functions in other methods
function getPointPosition(event)
{
var x_px_scr = event.clientX;
var y_px_scr = event.clientY;
alert(" Relative to the current screen X Axis offset " + x_px_scr);<span style="font-family: tahoma, helvetica, arial;">//Relative to devices (PC or mobile)</ span>
alert(" Relative to the current screen Y Axis offset " + y_px_scr);//Relative to devices (PC or mobile)
var x_Px_page = pointerX(event);
var y_Px_page = pointerY(event);
alert(" Relative to the entire page X Axis offset " + x_Px_page); //Relative to the browser
alert(" Relative to the entire page Y Axis offset " + y_Px_page); //Relative to the browser
}