HTML precise positioning: Scrollleft,scrollwidth,clientwidth,offsetwidth fully detailed description

Source: Internet
Author: User

Html:scrollleft,scrollwidth,clientwidth,offsetwidth specific means to fully explain exactly where the distance



ScrollHeight: Gets the height of the object scroll.

ScrollLeft: Sets or gets the distance between the left edge of the object and the leftmost of the currently visible content in the form

ScrollTop: Sets or gets the distance between the top of the object and the top of the visible content on the form

ScrollWidth: Gets the scrolling width of the object

Offsetheight: Gets the height of the object relative to the layout or parent coordinates specified by the parent coordinate OffsetParent property

Offsetleft: Gets the calculated left position of the object relative to the layout or the parent coordinate specified by the OffsetParent property

OffsetTop: Gets the computed top position of the object relative to the layout or the parent coordinate specified by the OffsetTop property

Event.clientx horizontal coordinates of relative documents

Event.clienty vertical coordinates of relative documents



Event.offsetx horizontal coordinates relative to the container

Event.offsety the vertical coordinate of the relative container

Document.documentElement.scrollTop The vertical scrolling value

Event.clientx+document.documentelement.scrolltop horizontal coordinates of relative documents + amount of vertical scrolling



The above mainly refers to IE, Firefox differences such as the following:

IE6.0, ff1.06+:

clientwidth = width + padding

clientheight = height + padding

offsetwidth = width + padding + border

offsetheight = height + padding + border

ie5.0/5.5:

ClientWidth = Width-border

ClientHeight = Height-border

offsetwidth = width

offsetheight = height

(Need to mention: the Margin property in CSS, and clientwidth, Offsetwidth, clientheight, offsetheight are irrelevant)

onmouseover when the mouse passes, trigger = the script function behind
onmouseout when the mouse leaves.


OnMouseUP when the mouse is pressed and lifted up.


OnMouseMove when the mouse moves.
OnMouseDown when the mouse is pressed ...

If obj is an HTML control.

Obj.offsettop refers to the calculation of the upper-side position of obj relative to the layout or the parent coordinate specified by the OffsetParent property, Integer. Unit pixels.

Obj.offsetleft refers to the computed left position of obj relative to the layout or the parent coordinate specified by the OffsetParent property. Integer, per pixel.

Obj.offsetwidth refers to the absolute width of the obj control itself, and does not contain parts that are not displayed because of overflow, that is, the actual width of the occupied, integer, unit pixels.

Obj.offsetheight refers to the absolute height of the obj control itself, and does not contain parts that are not displayed because of overflow, that is, the height of the actual inter-occupation, the integer type. Unit pixels.

Let's make a note of the offsetParent mentioned earlier.

OffsetParent gets a reference to the container object that defines the OffsetTop and Offsetleft properties of the object.

OffsetTop and offsetParent are very complex, different browsers have different interpretations, floating the explanation is different. So we generally just have to understand that you can get the absolute position of the control in the browser by both.

The above properties are also available in FireFox.

Also: What we're talking about here is the property value of the HTML control, not the value of document.body,document.body is interpreted differently in different browsers (in fact most environments are caused by different interpretations of document.body. Not due to different interpretations of offset)

We know that OffsetTop can get the position of the HTML element above or outside the element, Style.top is also able, the difference is:

First, OFFSETTOP returns a number, and Style.top returns a string, in addition to the number of units: px.

Second, OffsetTop only read, and Style.top can read and write.

Assuming that the top style is not specified for the HTML element, Style.top returns an empty string.

Offsetleft and Style.left, offsetwidth and Style.width, offsetheight and Style.height are the same.

ClientHeight
Everyone has no objection to clientheight, all feel is the height of the content visible area. That is to say, the height of this area of the content is visible in the page browser, usually the last toolbar below the status bar, regardless of the content of the page.

Offsetheight
IE, Opera feel offsetheight = clientheight + scroll bar + border.
NS, FF think offsetheight is the actual height of the Web content. Can be less than clientheight.

ScrollHeight
IE, Opera think ScrollHeight is the actual height of Web content, can be less than clientheight.
NS, FF think ScrollHeight is the height of the Web content, but the minimum value is clientheight.

To put it simply
ClientHeight is the height of the area through which the content is viewed by the browser.


NS, FF think Offsetheight and scrollheight are Web content height. Only when the content height of the Web page is less than or equal to clientheight. The value of ScrollHeight is clientheight, and offsetheight can be less than clientheight.
IE, Opera think offsetheight is visible area clientheight scroll bar and border. ScrollHeight is the actual height of the Web content.

Similarly
The explanations of clientwidth, offsetwidth and ScrollWidth are the same as above, just to change the height to the width.

Description
The above is based on the DTD HTML 4.01 Transitional. Assuming that the DTD XHTML 1.0 Transitional is different, the three values are the same value in XHTML. All represent the actual height of the content. Most browsers for the new version number support different interpreters based on the DOCTYPE specified on the page

ScrollTop is the height value of "volume" up. Demo Sample:

<div style= "Width:100px;height:100px;background-color: #FF0000; overflow:hidden;" id= "P" >
<div style= "Width:50px;height:300px;background-color: #0000FF;" id= "T" > assuming that scrolltop is set for p, the content may not be fully displayed. </div>
</div>
<script type= "Text/javascript" >
var p = document.getElementById ("P");
P.scrolltop = 10;
</script>

Because the scrolltop is set for the outer element p, the inner element is rolled up, and the part that is ScrollTop is the volume.

ScrollLeft is a similar principle.

We already know that offsetheight is the width of its own elements. The scrollheight is the absolute width of the inner element, including the hidden part of the inner element.

The scrollheight of p above is 300, while P's offsetheight is 100.

ScrollWidth is a similar principle.

IE and FireFox are fully supported, while Netscape 8 and Opera 7.6 Do not support scrolltop, scrollleft (except Document.body.scrollTop, Document.body.scrollLeft).

1.clientHeight, ClientWidth:
These two properties generally show the pixel height and width of the element content. Theoretically, these measurements do not take into account whatever is added through the stylesheet
The page margins, borders, and so on in the element.

2.clientleft,clienttop:
These two return the thickness of the border around the element, assuming that a border is not specified or the element is not positioned, his value is 0.

3.scrollleft,scrolltop:
Assuming that the element is capable of scrolling, you can get how far the elements are scrolled in both horizontal and vertical directions, in pixels, by these two properties.
For elements that cannot be scrolled, these values are always 0.

4.scrollheight,scrollwidth:
No matter how many objects are visible on the page, they get the overall.

5.style.left:
Offset of the left edge of the rectangle that contains the anchor element and its

6.style.pixelleft:
Returns the integer pixel value of the left boundary offset of the anchored element. Because the non-pixel value of the property returns a string that includes the unit, for example, 30px. This property allows you to handle numeric values in pixels individually.

7.STYLE:POSLETF:
Returns the value of the number of the left boundary offset of the anchored element, regardless of the unit specified by the corresponding style sheet element. Because the non-positional value of the property returns a string that includes the unit, for example, 1.2EM

Top,pixeltop,postop a few analogies.
Left: The distance between the left and right edge of the screen.
ClientLeft returns the distance between the Offsetleft property value of the object and the true value to the left of the current form
Offsetleft returns the left value of the layout or coordinates of the object relative to the parent object, which is the x-coordinate of the X-, y-axis positive direction of the parent object, the upper-right corner of the parents as the coordinate origin.
Pixelleft Sets or returns the position of the object relative to the left side of the form
ScrollWidth is the width of the actual contents of the object, not the edges of the envelope. varies depending on how much content is in the object (the actual width of the object may change if there is more content).


ClientWidth is the width of the object visible. Edges such as the scroll bar are not covered, and will change depending on the display size of the form.
Offsetwidth is the visible width of the object, and edges such as the package scroll bar change with the size of the form's display.
IE6.0, ff1.06+:
clientwidth = width + padding
clientheight = height + padding
offsetwidth = width + padding + border
offsetheight = height + padding + border
ie5.0/5.5:
ClientWidth = Width-border
ClientHeight = Height-border
offsetwidth = width
offsetheight = height
(You need to mention: the Margin property in CSS.) Unrelated to ClientWidth, offsetwidth, ClientHeight, offsetheight)

Offsetwidth: Is the offset width of the element relative to the parent element. equals Border+padding+width
ClientWidth: Is the visible width of the element.

equals Padding+width
ScrollWidth: Is the width of the element and contains the scrolling part.
The position of the offsetleft:html element relative to its own offsetparent element
ScrollLeft: Returns and sets the coordinate value of the current horizontal scrolling service

<input type= "button" value= "click" onclick= "Move ()" >
<div id= "D" style= "Background-color: #ff9966; Position:absolute; left:170px; Top:100px;width:300;height:300;overflow:scroll "
onclick= "alert (' offsetleft: ' +this.offsetleft)" >
<div style= "height:600;width:600" onclick= "alert (' offsetleft: ' +this.offsetleft) ' ></div>
</div>
<script language= "JavaScript" >
function Move ()
{
var D=document.getelementbyid ("D")
A=eval (20)
D.scrollleft+=a
}
</script>

Save as Web page, about implementation. Point button, scroll bar move
Click Div, first popular b about a place, then pop a relative to the position of the form

HTML precise positioning: Scrollleft,scrollwidth,clientwidth,offsetwidth fully detailed description

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.