Home > php教程 > PHP开发 > body text

The difference between offsetLeft and style.left of div

高洛峰
Release: 2016-12-24 15:22:35
Original
1191 people have browsed it

clientX event property returns the horizontal coordinate 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 position of the parent div is defined as relative and the position of the child div is defined as absolute, then the value of style.left of the child div is relative to the value of the parent div, which is the same as offsetLeft. The difference is:

1. style.left returns a string, such as 28px, and offsetLeft returns a value of 28. If you need to calculate the obtained value, it is more convenient to use offsetLeft.

2. style.left is read-write, offsetLeft is read-only, so to change the position of the div, you can only modify style.left.

3. The value of style.left needs to be defined in advance, otherwise the value obtained will be empty. And it must be defined in html. I have done experiments. If it is defined in css, the value of style.left is still empty. This is the problem I encountered at the beginning. I can't always get the value of style.left. offsetLeft can still be obtained without defining the position of the div in advance.

The above is a compilation of information on the difference between offsetLeft and style.left of div. Thank you for your support of this site!

For more articles related to the difference between offsetLeft and style.left of div, please pay attention to the PHP Chinese website!


Related labels:
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template