Copy codeThe Code is as follows:
// Obtain the element position
Function getLeft (obj ){
If (obj = null)
Return null;
Var mendingObj = obj;
Var mendingLeft = mendingObj. offsetLeft;
While (mendingObj! = Null & mendingObj. offsetParent! = Null & mendingObj. offsetParent. tagName! = "BODY "){
MendingLeft = mendingLeft + mendingObj. offsetParent. offsetLeft;
MendingObj = mendingObj. offsetParent;
}
Return mendingLeft;
};
Function getTop (obj ){
If (obj = null)
Return null;
Var mendingObj = obj;
Var mendingTop = mendingObj. offsetTop;
While (mendingObj! = Null & mendingObj. offsetParent! = Null & mendingObj. offsetParent. tagName! = "BODY "){
MendingTop = mendingTop + mendingObj. offsetParent. offsetTop;
MendingObj = mendingObj. offsetParent;
}
Return mendingTop;
};
// Obtain the cursor position
Function getMousePosition (event ){
Var position = {
MouseX: 0,
MouseY: 0
}
If (event. pageX! = Undefined ){
Position. MouseX = event. pageX;
Position. MouseY = event. pageY;
}
Else {
Var target = EventUtil. getTarget (event );
Position. MouseX = event. offsetX + getLeft (target );
Position. MouseY = event. offsetY + getTop (target );
}
Return position;