instance method Element#getLayout

View source on GitHub →

Element#getLayout([preCompute = false]) → Element.Layout
  • element (Element) – The element to be measured.
  • preCompute (Boolean) – Whether to compute all values at once. Default is false.

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.

If the preCompute argument is true, all properties will be measured when the layout object is instantiated. If you plan to measure several properties of an element's dimensions, it's probably worth it to get a pre-computed hash.

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
  • Instances of Element.Layout can 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.