CopyCode The Code is as follows: var X, Y;
// When the requirement is that the obtained coordinate value is relative to the body, use:
Function positionbody (event ){
Event = event | window. event;
// Obtain the horizontal value relative to the body position;
X = event. clientx
// Obtain the vertical value relative to the positioning of the body;
Y = event. clienty
}
// When the requirement is that the obtained coordinate value is relative to an object, use:
Function positionobj (event, ID ){
// Obtain the abscissa value of the object relative to the page. The ID is the ID of the object.
VaR thisx = Document. getelementbyid (ID). offsetleft;
// Obtain the abscissa value of the object relative to the page;
VaR thisy = Document. getelementbyid (ID). offsettop;
// Obtain the Page scrolling distance;
// Note: document.doc umentelement. scrolltop supports non-Google kernels, and document. Body. scrolltop supports Google kernels.
VaR thisscrolltop = document.doc umentelement. scrolltop + document. Body. scrolltop;
Event = event | window. event;
// Obtain the abscissa value relative to the object positioning = the abscissa value of the current page relative to the mouse-the abscissa value of the object;
X = event. clientx-thisx;
// Obtain the vertical value relative to the object positioning = the vertical coordinate value of the current mouse relative to the page-the object vertical coordinate value + the scroll height of the scroll bar;
Y = event. clienty-thisy + thisscrolltop;
}