Show:

A Context defines a top-level DOM element inside which other nodes (like Surfaces) are rendered.

The CSS class samsara-context is applied, which provides the minimal CSS necessary to create a performant 3D context (specifically preserve-3d).

The Context must be mounted to a DOM node via the mount method. If no node is specified it is mounted to document.body.

Constructor

DOM.Context

(
  • [options]
)

Parameters:

  • [options] Object optional

    Options

    • [enableScroll=false] Boolean optional

      Allow scrolling on mobile devices

Example:

 var context = Context();
        
         var surface = new Surface({
             size : [100,100],
             properties : {background : 'red'}
         });
        
         context.add(surface);
         context.mount(document.body)

Methods

add

(
  • Renderable
)
RenderTreeNode

Extends the render tree beginning with the Context's RootNode with a new node. Delegates to RootNode's add method.

Parameters:

Returns:

RenderTreeNode:

Wrapped node

emit

(
  • type
  • data
)
private

Used internally when context is subscribed to.

Parameters:

getPerspective

() Number

Get current perspective of this Context in pixels.

Returns:

Number:

Perspective in pixels

mount

(
  • node
)

Allocate contents of the context to a DOM node.

Parameters:

  • node Node

    DOM element

on

(
  • type
  • handler
)

Adds a handler to the type channel which will be executed on emit. These events should be DOM events that occur on the DOM node the context has been mounted to.

Parameters:

on

(
  • type
  • handler
)

Removes the handler from the type. Undoes the work of on.

Parameters:

setPerspective

(
  • perspective
  • [transition]
  • [callback]
)

Set current perspective of the context in pixels.

Parameters:

  • perspective Number

    Perspective in pixels

  • [transition] Object optional

    Transition definition

  • [callback] Function optional

    Callback executed on completion of transition

setPerspective

(
  • perspective
  • [transition]
  • [callback]
)

Set current perspective of the context in pixels.

Parameters:

  • perspective Number

    Perspective in pixels

  • [transition] Object optional

    Transition definition

  • [callback] Function optional

    Callback executed on completion of transition