Home > Web Front-end > HTML Tutorial > The difference between offsetLeft and style.left in div

The difference between offsetLeft and style.left in div

巴扎黑
Release: 2017-03-30 13:52:12
Original
1566 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 p is defined as relative and the position of the child p is defined as absolute, then the value of style.left of the child p is relative to the value of the parent p, 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 p, 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 p in advance.

The above is the detailed content of The difference between offsetLeft and style.left in div. For more information, please follow other related articles on 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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template