The distinction between offsetleft and style.left of Div _css/html

Source: Internet
Author: User

The ClientX event property returns the horizontal coordinates of the mouse pointer to the browser page (or client area) when the event is triggered.

The client area refers to the current window.

If the parent div's position is defined as relative, and the position of the child Div is defined as absolute, then the style.left value of the child div is relative to the parent Div, which is the same as the offsetleft, except that:

1. Style.left returns a string, such as 28px,offsetleft returns a value of 28, and if the value obtained is calculated, it is more convenient to use offsetleft.

2. Style.left is read-write, offsetleft is only readable, so to change the location of the Div, can only modify the Style.left.

3. The value of style.left needs to be defined beforehand, otherwise the value taken is null. and must be defined in HTML, I have done experiments, if the definition in CSS, style.left value is still empty, this is the problem I started to encounter, always do not get the value of Style.left. Offsetleft can still be fetched without having to define the div's location beforehand.

The above is the Div offsetleft and style.left difference data collation, follow-up continue to supplement the relevant information, thank you for your support of this site!

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.