.. _dojo/position: dojo.position ============= :Status: Draft :Version: 1.0 :Available: since 1.4 .. contents:: :depth: 2 Getter for the position and size of a DOM node. ============ Introduction ============ The dojo.position function is used to obtain position and size information about a DOM node. The type of information it returns is the width and height of the DOM node's border-box (or borderStart-to-borderEnd size), and absolute position (border-start) in the form of x and y coordinates. If the optional includeScroll boolean parameter (default=false) has the value true, then the returned x and y values are offsets from the document root (unaffected by window scrolling), otherwise they are relative to the current viewport. The return object looks like: { w: 300: h: 150, x: 700, y: 900, } for a node with a width of 300px and a height of 150px, with page absolute coordinates of 700px on the x-axis and 900px on the y-axis. ============== Usage Examples ============== ------------------------------------------------------------------------------------------------------------------------------------------------------------- Example 1: Center a small DOM node (with background image) over a larger DOM node (the frame) both vertically and horizontally relative to the document root ------------------------------------------------------------------------------------------------------------------------------------------------------------- .. cv-compound :: :version: 1.4-2.0 .. cv :: javascript .. cv :: html
.. cv :: css ---------------------------------------------------- Comparison of various DOM node position/size methods ---------------------------------------------------- To see the effect of dojo.position's includeScroll boolean parameter, scroll the window down and click the 15x120 content area. .. code-example :: :version: 1.4-2.0 .. javascript :: .. html ::attribute | ||||||
function | x | y | w | h | l | t |
dojo.position(node,true) | ||||||
dojo.position(node,false) | ||||||
dojo.marginBox(node) | ||||||
dojo.contentBox(node) | ||||||
dojo.coords(node,true) | ||||||
dojo.coords(node,false) |