instance method Element#getLayout
Element#getLayout([preCompute = false]) → Element.Layout
-
element(Element) – The element to be measured. -
preCompute(Boolean) – Whether to compute all values at once. Default isfalse.
Returns an instance of Element.Layout for measuring an element's
dimensions.
Note that this method returns a new Element.Layout object each time
it's called. If you want to take advantage of measurement caching,
retain a reference to one Element.Layout object, rather than calling
Element.getLayout whenever you need a measurement. You should call
Element.getLayout again only when the values in an existing
Element.Layout object have become outdated.
Remember that instances of Element.Layout compute values the first
time they're asked for and remember those values for later retrieval.
If you want to compute all an element's measurements at once, pass
Examples
var layout = $('troz').getLayout();
layout.get('width'); //-> 150
layout.get('height'); //-> 500
layout.get('padding-left'); //-> 10
layout.get('margin-left'); //-> 25
layout.get('border-top'); //-> 5
layout.get('border-bottom'); //-> 5
// Won't re-compute width; remembers value from first time.
layout.get('width'); //-> 150
// Composite values obtained by adding together other properties;
// will re-use any values we've already looked up above.
layout.get('padding-box-width'); //-> 170
layout.get('border-box-height'); //-> 510
Caveats
- Instances of
Element.Layoutcan measure the dimensions of an element hidden with CSS (display: none), but only if its parent element is visible.
This method can be called either as an instance method or as a generic method. If calling as a generic, pass the instance in as the first argument.