Some parameters about location used by Javascript drag-and-drop. Some parameters about location are used by Javascript drag-and-drop.
Before reading this article, take a look at the offsetParent attribute of the first Article Javascript drag-and-drop series Article 1. It is a good habit to step by step and is worth advocating.
Okay. Let's take a look at our contents today.
First, let's take a look at the element. offsetLeft attribute.
Supported browsers: Internet Explorer 4.0 +, Mozilla 1.0 +, Netscape 6.0 +, Opera 7.0 +, and Safari 1.0 +
Definition: returns a pixel value that represents the offset from the left edge of the current element to the left edge of the object returned by its offsetParent attribute.
Syntax:
LeftDis = element. offsetLeft
There is a Bug in the implementation of the offsetLeft attribute in Internet Explorer. Regardless of the value of the offsetParent attribute of the current element, it always calculates the offsetLeft with the Body element as the reference object. Fortunately, this Bug has been fixed in Intern Explorer 8 Beta 1. You still need to note that IE will calculate OffsetLeft from the Left-Border of the Body element as the standard, while other browsers will start from Left-Margin.
Test code 1:
Untitled Document
Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Test the OffsetParent attribute
In IE, after running this code, two windows are displayed, namely, "p" and "437", indicating offsetParent and offsetLeft respectively. In, the red border represents the Body element, and the black border represents the p element. This proves that, even in IE, offsetParent is not a Body element, the offsetLeft calculation is based on the Body element.