Home > Web Front-end > JS Tutorial > body text

js gets the absolute coordinates of the trigger event element in the entire web page (sample code)_javascript skills

WBOY
Release: 2016-05-16 17:09:19
Original
1141 people have browsed it

As shown below:

Copy code The code is 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; 
                
         // Get the absolute X coordinate of the control that triggered the event in the entire page
         function findPositionX(oElement) {
                                                                                                                                                                                                                               var posX = 0; oElement; oElement = oElement.offsetParent)
                                                              }
                                                                                        return posX;                                                   The absolute Y coordinate of the control that triggered the event on the entire page
function findPositionY(oElement) {
if (typeof (oElement.offsetParent) != 'undefined') {
for (var posY = 0; oElement ; oElement = oElement.offsetParent) {
                                                                                     }

Related labels:
js
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template