Js gets the sample code for the absolute coordinates of the trigger event element in the entire web page

  • 2020-03-30 00:52:21
  • OfStack

As follows:

 //Return array type
        function findPosition(oElement) {//OElement current element
            if (typeof (oElement.offsetParent) != 'undefined') {
                for (var posX = 0, posY = 0; oElement; oElement = oElement.offsetParent) {
                    posX += oElement.offsetLeft;
                    posY += oElement.offsetTop;
                }
            }
            var array = [posX, posY];
            return array;
        }
        //Gets the absolute X coordinates of the control that triggered the event on the entire page
        function findPositionX(oElement) {
            if (typeof (oElement.offsetParent) != 'undefined') {
                for (var posX = 0; oElement; oElement = oElement.offsetParent)
                {
                    posX += oElement.offsetLeft;
                }
            }
            return posX;
        }
        //Gets the absolute Y coordinate of the control that triggers the event on the entire page
        function findPositionY(oElement) {
            if (typeof (oElement.offsetParent) != 'undefined') {
                for (var posY = 0; oElement; oElement = oElement.offsetParent) {
                    posY += oElement.offsetTop;
                }
            }
            return posY;
        } 

Related articles: