Module: rgjs/rect

RGJS6 Rect module.

Methods


<static> domRect(element [, forceInner])

Get DomRect of an element.
Includes additional offsetWidth and offsetHeight properties. Polyfills DomRect.x and DomRect.y for IE.

Parameters:
Name Type Argument Description
element element

The element to measure.

forceInner boolean <optional>

Optional. Force-ignore paddings, borders and margins, useful for border-box sized elems.

Returns:

The DomRect of the element. Note:

Type
object
Example
rgjs.rect.domRect(body_element); // {x: 8, y: 8, width: 830, height: 427.875, top: 8, right: 838, bottom: 435.875, left:8, offsetHeight: 428, offsetWidth: 830}

<static> innerHeight(element [, _cs])

Get inner height of an element (excluding padding, border, margin).

Parameters:
Name Type Argument Description
element element

The element to measure.

_cs object <optional>

Optional. Computed style of element (CSSStyleDeclaration).

Returns:

The inner height of the element.

Type
number
Example
rgjs.rect.innerHeight(body_element); // 1024

<static> innerRect(element [, _cs])

Get inner rect of an element (excluding padding, border, margin).

Parameters:
Name Type Argument Description
element element

The element to measure.

_cs object <optional>

Optional. Computed style of element (CSSStyleDeclaration).

Returns:

The inner rect of the element: {width, height}

Type
object
Example
rgjs.rect.innerRect(body_element); // {width: 1024, height: 768}

<static> innerWidth(element [, _cs])

Get inner width of an element (excluding padding, border, margin).

Parameters:
Name Type Argument Description
element element

The element to measure.

_cs object <optional>

Optional. Computed style of element (CSSStyleDeclaration).

Returns:

The inner width of the element.

Type
number
Example
rgjs.rect.innerWidth(body_element); // 1024

<static> isElementInViewport(el)

Check if element is in the viewport.
See https://stackoverflow.com/a/26039199/6350400

Parameters:
Name Type Description
el element

The element.

Returns:

True or false.

Type
boolean
Example
rgjs.rect.isElementInViewport(some_element)

<static> isElementPartiallyInViewport(el)

Check if element is (partially) in the viewport.
See https://stackoverflow.com/a/26039199/6350400

Parameters:
Name Type Description
el element

The element.

Returns:

True or false.

Type
boolean
Example
rgjs.rect.isElementPartiallyInViewport(some_element)

<static> offsetLeft(element [, parent])

Get an element's offsetLeft relative to a parent element.

Parameters:
Name Type Argument Default Description
element element

An element.

parent element <optional>
window

Optional. The element's parent. Defaults to 'window'.

Returns:

The element's offsetLeft relative to parent.

Type
number
Examples
// Get offset relative to window
rgjs.obj.offsetLeft(some_element)
// Get offset relative to parent
rgjs.obj.offsetLeft(some_element, some_element.parentNode)

<static> offsetTop(element [, parent])

Get an element's offsetTop relative to a parent element.

Parameters:
Name Type Argument Default Description
element element

An element.

parent element <optional>
window

Optional. The element's parent. Defaults to 'window'.

Returns:

The element's offsetTop relative to parent.

Type
number
Examples
// Get offset relative to window
rgjs.obj.offsetTop(some_element)
// Get offset relative to parent
rgjs.obj.offsetTop(some_element, some_element.parentNode)