02.06.2013 Views

DOM Traversal Methods

DOM Traversal Methods

DOM Traversal Methods

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

Dimensions Plug-In<br />

•<br />

relativeTo (optional): An HTML element representing the ancestor<br />

element relative to which the matched element will be offset. Default is<br />

document.body.<br />

Parameters (Second Version)<br />

•<br />

options: A map of settings to configure the way the offset is calculated.<br />

°<br />

°<br />

°<br />

°<br />

°<br />

°<br />

°<br />

margin (optional): A Boolean indicating whether to include<br />

the element's margin in the calculations. Default is true.<br />

border (optional): A Boolean indicating whether to include<br />

the element's border in the calculations. Default is false.<br />

padding (optional): A Boolean indicating whether to include<br />

the element's padding in the calculations. Default is false.<br />

scroll (optional): A Boolean indicating whether to include<br />

the scroll offsets of all ancestor elements in the calculations.<br />

Default is true.<br />

lite (optional): A Boolean indicating whether to use<br />

offsetLite instead of offset. Default is false.<br />

relativeTo (optional): An HTML element representing the<br />

ancestor element relative to which the matched element will<br />

be offset. Default is document.body.<br />

returnObject: An object in which to store the return value.<br />

When the second version of the method is used, the chain will<br />

not be broken, and the result will be assigned to this object.<br />

Return Value (First Version)<br />

An object containing values for top, left, and optionally scrollTop<br />

and scrollLeft.<br />

Return Value (Second Version)<br />

The jQuery object, for chaining purposes.<br />

Description<br />

The .offset method allows us to locate the top and left positions of any element<br />

anywhere on the page, whether its position is static or relative, absolute or<br />

fixed, and regardless of the position of scrollbars. With options for factoring margin,<br />

border, padding, and scroll into the calculation, .offset() provides great flexibility<br />

as well as accuracy.<br />

The following series of images demonstrates the different values returned by<br />

.offset() depending on how the options are set.<br />

[ 208 ]

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

Saved successfully!

Ooh no, something went wrong!