04.11.2015 Views

javascript

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Scroll Dimensions<br />

Chapter 11: DOM Levels 2 and 3<br />

The last set of dimensions is scroll dimensions , which provide information about an element whose<br />

content is scrolling. Some elements, such as the < html > element, scroll automatically without needing<br />

any additional code, whereas other elements can be made to scroll by using the CSS overflow property.<br />

The four scroll dimension properties are as follows:<br />

❑<br />

❑<br />

❑<br />

❑<br />

scrollHeight — The total height of the content if there were no scrollbars present.<br />

scrollLeft — The number of pixels that are hidden to the left of the content area. This<br />

property can be set to change the scroll position of the element.<br />

scrollTop — The number of pixels that are hidden in the top of the content area. This property<br />

can be set to change the scroll position of the element.<br />

scrollWidth — The total width of the content if there were no scrollbars present.<br />

Figure 11 - 3 illustrates these properties.<br />

scrollWidth<br />

hidden content<br />

scrollTop<br />

scrollHeight<br />

border<br />

content padding<br />

Figure 11-3<br />

scrollLeft<br />

The scrollWidth and scrollHeight properties are useful for determining the actual dimensions<br />

of the content in a given element. For example, the < html > element is considered the element that<br />

scrolls the viewport in a web browser (the < body > element in IE versions prior to 6 running in<br />

quirks mode). Therefore, the height of an entire page that has a vertical scrollbar is document<br />

.documentElement.scrollHeight .<br />

339

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!