Since scrollTop is set for the outer element p, the inner element will scroll upward. scrollLeft is similar. We already know that offsetHeight is the width of its own element. And scrollHeight is the absolute width of the inner element, including the hidden part of the inner element. In the above, the scrollHeight of p is 300, and the offsetHeight of p is 100. scrollWidth is similar. IE and FireFox fully support, while Netscape and Opera do not support scrollTop and scrollLeft (except document.body). Title: offsetTop, offsetLeft, offsetWidth, offsetHeight
4. clientLeft Returns the distance between the offsetLeft attribute value of the object and the real value to the left side of the current window, you can Understood as the length of the border I have always been confused about the methods of offsetLeft, offsetTop, scrollLeft, and scrollTop. I spent a day studying them carefully. The following results were obtained: 1.offsetTop: The distance from the current object to the top of its superior layer. cannot be assigned a value. Please set the distance from the object to the top of the page. Use the style.top attribute.
2.offsetLeft: The distance between the current object and the left side of its parent layer. Cannot be assigned a value. Set the object to the left of the page Please use the style.left attribute for the distance.
3.offsetWidth: The width of the current object. The difference between and the style.width attribute is: if the width of the object is set The fixed value is the percentage width, no matter the page becomes larger or smaller, style.width returns this percentage, while offsetWidth returns the width value of the object in different pages instead of the percentage value
4. offsetHeight: The difference between and the style.height property is that if the width of the object is set to a percentage height, no matter the page becomes larger or smaller, style.height will return this percentage, while offsetHeight will return the percentage. The height value of the object in different pages instead of the percentage value
5.offsetParent : The parent object of the current object. Note. If the object is included in a DIV , this DIV will not be regarded as the upper level of this object (that is, the upper level of the object will skip the DIV object). When the upper level is a Table, there will be no problem. Using this attribute, you can get the location of the current object. Absolute position in pages of different sizes. Get the absolute position script code
function GetPosition(obj ) { var left = 0; var top = 0;
while(obj != document.body) { left = obj.offsetLeft; top = obj.offsetTop;
obj = obj.offsetParent; }
alert("Left Is : " left "rn" "Top Is : " top); }
6.scrollLeft: The distance from the far left side of the object to the left side of the object within the range displayed in the current window. That is, when a horizontal scroll bar appears, the distance the scroll bar is pulled.
7.scrollTop The distance from the top of the object to the top edge of the object within the range displayed in the current window. That is, when a vertical scroll bar appears, the distance the scroll bar is pulled. Here we talk about the interpretation of clientHeight, offsetHeight and scrollHeight of document.body by four browsers. Here we are talking about document.body. If it is an HTML control, it is different. Click here to view. The four browsers are IE (Internet Explorer), NS (Netscape), Opera, and FF (FireFox).
clientHeight No one has any objection to clientHeight. They all think it is the height of the visible area of the content, which means the height of the area where the content can be seen in the page browser. , generally the area below the last toolbar to above the status bar, has nothing to do with the page content.
offsetHeight IE and Opera consider offsetHeight = clientHeight scroll bar border. NS and FF consider offsetHeight to be the actual height of the web page content, which can be smaller than clientHeight.
scrollHeight IE and Opera believe that scrollHeight is the actual height of the web page content and can be smaller than clientHeight. NS and FF consider scrollHeight to be the height of web page content, but the minimum value is clientHeight.
Simply put clientHeight is the height of the area where the content is viewed through the browser. NS and FF believe that offsetHeight and scrollHeight are both web page content heights, but when the web page content height is less than or equal to clientHeight, the value of scrollHeight is clientHeight, and offsetHeight can be less than clientHeight. IE and Opera believe that offsetHeight is the visible area clientHeight scroll bar plus
Statement:
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