jQuery in Action
The Dimensions Plugin
291
To ensure that the values returned from this method are accurate, we express
dimensions and positions of the elements on the page in pixel values. The default
settings for this method usually give an accurate representation; but, if we're
more interested in speed than in accuracy (for example, if we're using this
method on many elements in a tight loop), we might want to explore how the
dimensions and positions of the elements on the page in pixel values. The default
settings for this method usually give an accurate representation; but, if we're
more interested in speed than in accuracy (for example, if we're using this
method on many elements in a tight loop), we might want to explore how the
lite
option and other settings work in our situation.
Let's move away from the realm of positions and measurements and look at
another plugin that's helpful on pages with lots of dynamic elements and event
handling.
handling.
Command syntax: offset
offset(options,results)
Returns offset information for the first element in the wrapped set. By default, the informa-
tion is relative to the <body> element, and the manner in which it's calculated is controlled
by the settings in the options parameter.
tion is relative to the <body> element, and the manner in which it's calculated is controlled
by the settings in the options parameter.
Parameters
options
(Object) An object hash containing settings that control how the method per-
forms its calculations. The possible values are as follows:
forms its calculations. The possible values are as follows:
relativeTo
--(Element) Specifies an ancestor element of the wrapped ele-
ment to base the relative offset on. This element should have a position
value of relative or absolute. If omitted, the default is the <body> element.
value of relative or absolute. If omitted, the default is the <body> element.
lite
--(Boolean) Specifies that certain browser-specific optimizations be
skipped in the calculations. This will increase performance at the price of
accuracy. Defaults to false.
accuracy. Defaults to false.
scroll
--(Boolean) Specifies whether scroll offsets should be taken into
account. Defaults to true.
padding
--(Boolean) Specifies whether padding should be included in the
calculation. Defaults to false.
border
--(Boolean) Specifies whether borders should be included in the cal-
culation. Defaults to false.
margin
--(Boolean) Specifies whether margins should be included in the cal-
culation. Defaults to true.
results
(Object) An optional object to receive the results of the method. If omitted, a
new object is created, populated with the results and returned as the value of
the method. If specified, the passed object is augmented with the result prop-
erties, and the wrapped set is returned from the method. This is useful when
you want the method to participate in a jQuery command chain.
new object is created, populated with the results and returned as the value of
the method. If specified, the passed object is augmented with the result prop-
erties, and the wrapped set is returned from the method. This is useful when
you want the method to participate in a jQuery command chain.
Returns
The wrapped set if a results object is specified, the results object if not. The results
object contains properties top and left, as well as scrollTop and scrollLeft unless the
scroll
The wrapped set if a results object is specified, the results object if not. The results
object contains properties top and left, as well as scrollTop and scrollLeft unless the
scroll
option is explicitly set to false.