Deep Learning about DOM element locating attributes

Source: Internet
Author: User
Deep Learning about DOM element locating attributes

Published by sansan at pm under Front End | Front-End

When I used to write JS programs, I often encountered locating problems. But every time I see half of it, it's okay to find the desired attribute.

Today, I am so worried that it will take some time to thoroughly understand him.

The following content is not surprising if you are familiar with it, because it is a summary of articles from many predecessors.

  Width and height

JQuery ('# elem'). width () // gets the width defined by CSS.

JQuery ('# elem'). height () // gets the height defined by CSS.

ClientWidth = width + padding

ClientHeight = height + padding

OffsetWidth = width + padding + border

OffsetHeight = height + padding + border

ScrollWidth // The scroll width of the object

ScrollHeight // The scroll height of the object

ClientLeft // borderLeftWidth

ClientTop // borderTopWidth

 

Left, Top

ScrollTop // The distance between the left boundary of the object and the leftmost end of the currently visible content in the window

ScrollLeft // The distance between the top of the object and the top of the visible content in the window

OffsetTop // The position at the top of the parent node

OffsetLeft // left position relative to the parent node

  Parent node

ParentNode // is the parent node. Understand and apply it in terms of structure.

OffsetParent // relative to the parent node. Understand and apply the layout.

 

The x and y coordinates of the mouse relative to the browser

E. clientX, e. clientY

 

The x and y coordinates of the mouse relative to the trigger event container

E. offsetX, e. offsetY // for IE

E. layerX, e. layerY // for FF

 

Vertical scroll Value

Document.doc umentElement. scrollTop

Document. body. scrollTop (Quirks Mode)

 

The x and y coordinates of the mouse relative to the top of the page

PageX, pageY // for FF

E. clientX + document.doc umentElement. scrollLeft // for IE

E. clientY + document.doc umentElement. scrollTop // for IE

 

Absolute coordinates relative to the padding of the Body

JQuery ('# elem'). offset ();

 

At last, we will attach an old figure.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.