04.11.2015 Views

javascript

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

Element Dimensions<br />

The following properties and methods are not part of the DOM Level 2 Style specification but are<br />

nonetheless related to styles on HTML elements. The DOM stops short of describing ways to determine<br />

the actual dimensions of elements on a page. IE first introduced several properties to expose<br />

dimension information to developers. These properties have now been incorporated into all of the major<br />

browsers.<br />

Offset Dimensions<br />

The first set of properties deals with offset dimensions , which incorporate all of the visual space that an<br />

element takes up on the screen. An element ’ s visual space on the page is made up of its height and<br />

width, including all padding, scrollbars, and borders (but not including margins). The following four<br />

properties are used to retrieve offset dimensions:<br />

❑<br />

❑<br />

❑<br />

❑<br />

offsetHeight — The amount of vertical space, in pixels, taken up by the element, including its<br />

height, the height of a horizontal scrollbar (if visible), the top border height, and the bottom<br />

border height<br />

offsetLeft — The number of pixels between the element ’ s outside left border and the<br />

containing element ’ s inside left border<br />

offsetTop — The number of pixels between the element ’ s outside top border and the<br />

containing element ’ s inside top border<br />

offsetWidth — The amount of horizontal space taken up by the element, including its width,<br />

the width of a vertical scrollbar (if visible), the left border width, and the right border width<br />

The offsetLeft and offsetTop properties are in relation to the containing element, which is stored<br />

in the offsetParent property. The offsetParent may not necessarily be the same as the parentNode .<br />

For example, the offsetParent of a < td > element is the < table > element that it ’ s an ancestor of,<br />

because the < table > is the first element in the hierarchy that provides dimensions. Figure 11-1 illustrates<br />

the various dimensions these properties represent.<br />

offsetParent<br />

offsetTop<br />

offsetLeft<br />

border<br />

padding<br />

content<br />

offsetHeight<br />

offsetWidth<br />

Figure 11 - 1<br />

336

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

Saved successfully!

Ooh no, something went wrong!