How to locate a fixed layer in js

Source: Internet
Author: User

You need to obtain the coordinates of Some HTML objects to set the coordinates of the Target layer more flexibly. Here you can use the document. body. scrollTop and other attributes, but these attributes are included in the standard web page of xhtml! The value of the DOCTYPE...> label is 0. If this label is not used, everything is normal. How can we get the coordinates of the body in xhtml? Of course, we can use document.doc umentElement to replace document. body as follows:
Copy codeThe Code is as follows:
Var top=document.doc umentElement. scrollTop | document. body. scroolTop;

| In js is a good thing. It can be used not only in the if condition statement, but also in variable assignment. The preceding example can be written in the following format:
Copy codeThe Code is as follows:
Var top=document.doc umentElement. scrollTop? Document.doc umentElement. scrollTop: document. body. scrollTop;

In this way, writing can have good compatibility. Note that if you do not declare the value of document.doc umentElement. scrollTop, 0 is displayed.



To obtain the ordinate position of the scroll bar on the current page: Use
Document.doc umentElement. scrollTop instead
Document. body. scrollTop;
Document.doc umentElement obtains html tags,
Document. body obtains the body tag;
In the standard w3c, the value of document.body.scrolltopic is 0, and the value of document.doc umentElement. scrollTop is used;
If we want to locate the absolute location of the mouse relative to the page, most of what we get in the search engine will let you use
Event. clientX + document. body. scrollLeft, event. clientY + document. body. scrollTop;
It's strange if you find that the mouse is away from your imagination, because IE5.5 does not support document. body. scrollX objects anymore.
So we need to add a sentence;
Copy codeThe Code is as follows:
If (document. body & document. body. scrollTop & document. body. scrollLeft)
{
Top = document. body. scrollTop;
Left = document. body. scrollleft;
}
If (document.doc umentElement & document.doc umentElement. scrollTop & document.doc umentElement. scrollLeft)
{
Top=document.doc umentElement. scrollTop;
Left+document.doc umentElement. scrollLeft;
}

The following describes the usage of some parameters:
Visible area width of the webpage: document. body. clientWidth;
Visible area height of the webpage: document. body. clientHeight;
Visible area width of the webpage: document. body. offsetWidth; (including the width of the edge );
Visible area height of the webpage: document. body. offsetHeight; (including the width of the edge );
Full text width of the webpage: document. body. scrollWidth;
Webpage text height: document. body. scrollHeight;
The height of the page to be rolled: document. body. scrollTop;
Left of the webpage to be rolled: document. body. scrollLeft;
On the webpage body part: windows. screenTop;
Page body part left: windows. screenLeft;
Screen Resolution height: windows. screen. height;
Screen Resolution width: windows. screen. widht;
Available screen workspace Height: windows. screen. availHeight;
Available workspace width: windows. screen. availWidth;
Obtain the scroll height of an object: scrollHeight;
Sets or obtains the distance between the left-side border of the object and the leftmost side of the currently visible content in the window: scrollLeft;
Sets or obtains the distance between the top of the object and the top of the visible content in the window: scrollTop;
Obtain the scroll width of an object: scrollWidth;
Obtains the height of an object relative to the layout or the parent coordinate specified by the parent coordinate: offsetParent;
Obtain the left-side position of an object relative to the layout or the parent coordinate specified by the offsetParent attribute: offsetLeft;
Obtains the top position of an object relative to the layout or the parent coordinate specified by the offsetTop attribute: offsetTop;
Event. clientX: the horizontal coordinate relative to the document;
Event. clientY: the vertical coordinate relative to the document;
Event. offsetX: horizontal coordinate relative to the container;
Event. offsetY: the vertical coordinate relative to the container;
Document.doc umentElement. scrollTop: Set the vertical height of the scroll.
Event. clientX + document.doc umentElement. scrollTop: the horizontal position of the document and the scroll volume in the vertical direction;

Related Article

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.