Javascript drag series Article 2

Source: Internet
Author: User
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.

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.