Reference size()

size()

Sets the element's width and height.

Calling myElement.size() without an argument returns the element's size as an object with the properties width and height. For example, { width: 20, height: 10 }.

The first parameter, width, is optional. It's a number used to set the element's width. Calling myElement.size(10)

The second parameter, 'height, is also optional. It's a number used to set the element's height. For example, callingmyElement.size(20, 10)` sets the element's width to 20 pixels and height to 10 pixels.

The constant AUTO can be used to adjust one dimension at a time while maintaining the aspect ratio, which is width / height. For example, consider an element that's 200 pixels wide and 100 pixels tall. Calling myElement.size(20, AUTO) sets the width to 20 pixels and height to 10 pixels.

Note: In the case of elements that need to load data, such as images, wait to call myElement.size() until after the data loads.

Examples

Syntax

size()
size([w], [h])

Parameters

w
Number|Constant:

width of the element, either AUTO, or a number.

h
Number|Constant:

height of the element, either AUTO, or a number.

Notice any errors or typos? Please let us know. Please feel free to edit src/dom/dom.js and open a pull request!

Related References