DOM utility class.
Provides a useful Window and Element functions as well as cross-browser compatibility buffer.
Some code originally derived from verge.
Some parts were inspired by the research of Ryan Van Etten, released under MIT License 2013.
The size of the document / Layout viewport.
This incorrectly reports the dimensions in IE.
The properties change dynamically.
Name | Type | Description |
---|---|---|
width | number | Document width in pixels. |
height | number | Document height in pixels. |
The bounds of the Layout viewport, as discussed in
A tale of two viewports — part two;
but honoring the constraints as specified applicable viewport meta-tag.
The bounds returned are not guaranteed to be fully aligned with CSS media queries (see
What size is my viewport?).
This is not representative of the Visual bounds: in particular the non-primary axis will
generally be significantly larger than the screen height on mobile devices when running with a
constrained viewport.
The properties change dynamically.
Name | Type | Description |
---|---|---|
width | number | Viewport width in pixels. |
height | number | Viewport height in pixels. |
A cross-browser window.scrollX.
A cross-browser window.scrollY.
The bounds of the Visual viewport, as discussed in
A tale of two viewports — part one
with one difference: the viewport size excludes scrollbars, as found on some desktop browsers.
Supported mobile:
iOS/Safari, Android 4, IE10, Firefox OS (maybe not Firefox Android), Opera Mobile 16
The properties change dynamically.
Name | Type | Description |
---|---|---|
x | number | Scroll, left offset - eg. "scrollX" |
y | number | Scroll, top offset - eg. "scrollY" |
width | number | Viewport width in pixels. |
height | number | Viewport height in pixels. |
Get the Visual viewport aspect ratio (or the aspect ratio of an object or element)
Name | Type | Argument | Default | Description |
---|---|---|---|---|
object | DOMElement | Object | <optional> | (visualViewport) | The object to determine the aspect ratio for. Must have public |
The aspect ratio.
A cross-browser element.getBoundingClientRect method with optional cushion.
Returns a plain object containing the properties top/bottom/left/right/width/height
with respect to the top-left corner of the current viewport.
Its properties match the native rectangle.
The cushion parameter is an amount of pixels (+/-) to cushion the element.
It adjusts the measurements such that it is possible to detect when an element is near the viewport.
Name | Type | Argument | Description |
---|---|---|---|
element | DOMElement | Object | The element or stack (uses first item) to get the bounds for. | |
cushion | number | <optional> | A +/- pixel adjustment amount. |
A plain object containing the properties top/bottom/left/right/width/height
or false
if a non-valid element is given.
Get the [absolute] position of the element relative to the Document.
The value may vary slightly as the page is scrolled due to rounding errors.
Name | Type | Argument | Description |
---|---|---|---|
element | DOMElement | The targeted element that we want to retrieve the offset. | |
point | Phaser.Point | <optional> | The point we want to take the x/y values of the offset. |
Returns the device screen orientation.
Orientation values: 'portrait-primary', 'landscape-primary', 'portrait-secondary', 'landscape-secondary'.
Order of resolving:
See
Name | Type | Argument | Default | Description |
---|---|---|---|---|
primaryFallback | string | <optional> | (none) | Specify 'screen', 'viewport', or 'window.orientation'. |
Tests if the given DOM element is within the Layout viewport.
The optional cushion parameter allows you to specify a distance.
inLayoutViewport(element, 100) is true
if the element is in the viewport or 100px near it.
inLayoutViewport(element, -100) is true
if the element is in the viewport or at least 100px near it.
Name | Type | Argument | Description |
---|---|---|---|
element | DOMElement | Object | The DOM element to check. If no element is given it defaults to the Phaser game canvas. | |
cushion | number | <optional> | The cushion allows you to specify a distance within which the element must be within the viewport. |
True if the element is within the viewport, or within cushion
distance from it.
© 2016 Richard Davey, Photon Storm Ltd.
Licensed under the MIT License.
http://phaser.io/docs/2.6.2/Phaser.DOM.html