Class: DOM

Phaser. DOM

new DOM()

DOM utility class.

Provides a useful Window and Element functions as well as cross-browser compatibility buffer.

Source - system/DOM.js, line 3

Members

<internal, static, readonly> documentHeight :number

Gets the document height in pixels.

Internal:
  • This member is internal (protected) and may be modified or removed in the future.
Source - system/DOM.js, line 341

<internal, static, readonly> documentWidth :number

Gets the document width in pixels.

Internal:
  • This member is internal (protected) and may be modified or removed in the future.
Source - system/DOM.js, line 322

<internal, static, readonly> scrollX :number

A cross-browser window.scrollX.

Internal:
  • This member is internal (protected) and may be modified or removed in the future.
Source - system/DOM.js, line 248

<internal, static, readonly> scrollY :number

A cross-browser window.scrollY.

Internal:
  • This member is internal (protected) and may be modified or removed in the future.
Source - system/DOM.js, line 264

<internal, static, readonly> viewportHeight :number

Gets the viewport height in pixels.

Internal:
  • This member is internal (protected) and may be modified or removed in the future.
Source - system/DOM.js, line 301

<internal, static, readonly> viewportWidth :number

Gets the viewport width in pixels.

Internal:
  • This member is internal (protected) and may be modified or removed in the future.
Source - system/DOM.js, line 280

Methods

<static> getAspectRatio(object) → {number}

Get the viewport aspect ratio (or the aspect ratio of an object or element)

Parameters:
Name Type Argument Default Description
object DOMElement | Object <optional>
(viewport)

Optional object. Must have public width and height properties or methods.

Returns:
number -

The aspect ratio.

Source - system/DOM.js, line 108

<static> getBounds(element, cushion) → {Object|boolean}

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.

Parameters:
Name Type Argument Description
element DOMElement | Object

The element or stack (uses first item) to get the bounds for. If none given it defaults to the Phaser game canvas.

cushion number <optional>

A +/- pixel adjustment amount.

Returns:
Object | boolean -

A plain object containing the properties top/bottom/left/right/width/height or false if a non-valid element is given.

Source - system/DOM.js, line 56

<static> getOffset(element, point) → {Phaser.Point}

Get the DOM offset values of any given element

Parameters:
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:
  • A point objet with the offsetX and Y as its properties.
Source - system/DOM.js, line 17

<internal, static> getScreenOrientation(primaryFallback)

Returns the device screen orientation.

Orientation values: 'portrait-primary', 'landscape-primary', 'portrait-secondary', 'landscape-secondary'.

Order of resolving: - Screen Orientation API, or variation of - Future track. Most desktop and mobile browsers. - Screen size ratio check - If fallback is 'screen', suited for desktops. - Viewport size ratio check - If fallback is 'viewport', suited for mobile. - window.orientation - If fallback is 'window.orientation', non-recommended track. - Media query - Viewport size ratio check (probably only IE9 and legacy mobile gets here..)

See - https://w3c.github.io/screen-orientation/ (conflicts with mozOrientation/msOrientation) - https://developer.mozilla.org/en-US/docs/Web/API/Screen.orientation (mozOrientation) - http://msdn.microsoft.com/en-us/library/ie/dn342934(v=vs.85).aspx - https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Testing_media_queries - http://stackoverflow.com/questions/4917664/detect-viewport-orientation - http://www.matthewgifford.com/blog/2011/12/22/a-misconception-about-window-orientation

Parameters:
Name Type Argument Default Description
primaryFallback string <optional>
(none)

Specify 'screen', 'viewport', or 'window.orientation'.

Internal:
  • This member is internal (protected) and may be modified or removed in the future.
Source - system/DOM.js, line 173

<static> inViewport(element, cushion) → {boolean}

Tests if the given DOM element is within the viewport.

The optional cushion parameter allows you to specify a distance.

inViewport(element, 100) is true if the element is in the viewport or 100px near it. inViewport(element, -100) is true if the element is in the viewport or at least 100px near it.

Parameters:
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.

Returns:
boolean -

True if the element is within the viewport, or within cushion distance from it.

Source - system/DOM.js, line 152

<internal> getViewport()

Get the viewport dimensions.

Internal:
  • This member is internal (protected) and may be modified or removed in the future.
Source - system/DOM.js, line 137
Phaser Copyright © 2012-2014 Photon Storm Ltd.
Documentation generated by JSDoc 3.3.0-dev on Sat Nov 15 2014 19:54:33 GMT-0000 (GMT) using the DocStrap template.