Namespace: DOM

Phaser. DOM

Classes

RequestAnimationFrame

Methods


<static> AddToDOM(element [, parent])

Adds the given element to the DOM. If a parent is provided the element is added as a child of the parent, providing it was able to access it. If no parent was given it falls back to using document.body.

Parameters:
Name Type Argument Description
element HTMLElement

The element to be added to the DOM. Usually a Canvas object.

parent string | HTMLElement <optional>

The parent in which to add the element. Can be a string which is passed to getElementById or an actual DOM object.

Since: 3.0.0
Source: src/dom/AddToDOM.js (Line 7)
Returns:

The element that was added to the DOM.

Type
HTMLElement

<static> DOMContentLoaded(callback)

Inspects the readyState of the document. If the document is already complete then it invokes the given callback. If not complete it sets up several event listeners such as deviceready, and once those fire, it invokes the callback. Called automatically by the Phaser.Game instance. Should not usually be accessed directly.

Parameters:
Name Type Description
callback ContentLoadedCallback

The callback to be invoked when the device is ready and the DOM content is loaded.

Since: 3.0.0
Source: src/dom/DOMContentLoaded.js (Line 13)

<static> GetInnerHeight(iOS)

Attempts to determine the document inner height across iOS and standard devices. Based on code by @tylerjpeterson

Parameters:
Name Type Description
iOS boolean

Is this running on iOS?

Since: 3.16.0
Source: src/dom/GetInnerHeight.js (Line 7)
Returns:

The inner height value.

Type
number

<static> GetScreenOrientation(width, height)

Attempts to determine the screen orientation using the Orientation API.

Parameters:
Name Type Description
width number

The width of the viewport.

height number

The height of the viewport.

Since: 3.16.0
Source: src/dom/GetScreenOrientation.js (Line 9)
Returns:

The orientation.

Type
string

<static> GetTarget(element)

Attempts to get the target DOM element based on the given value, which can be either a string, in which case it will be looked-up by ID, or an element node. If nothing can be found it will return a reference to the document.body.

Parameters:
Name Type Description
element HTMLElement

The DOM element to look-up.

Since: 3.16.0
Source: src/dom/GetTarget.js (Line 7)

<static> ParseXML(data)

Takes the given data string and parses it as XML. First tries to use the window.DOMParser and reverts to the Microsoft.XMLDOM if that fails. The parsed XML object is returned, or null if there was an error while parsing the data.

Parameters:
Name Type Description
data string

The XML source stored in a string.

Since: 3.0.0
Source: src/dom/ParseXML.js (Line 7)
Returns:

The parsed XML data, or null if the data could not be parsed.

Type
DOMParser | ActiveXObject

<static> RemoveFromDOM(element)

Attempts to remove the element from its parentNode in the DOM.

Parameters:
Name Type Description
element HTMLElement

The DOM element to remove from its parent node.

Since: 3.0.0
Source: src/dom/RemoveFromDOM.js (Line 7)