craftyjs.github.com

DOM

Draws entities as DOM nodes, specifically <DIV>s.

Back to top

._element

The DOM element used to represent the entity.

Back to top

.getDomId

public this .getId()

Get the Id of the DOM element used to represent the entity.

Back to top

.DOM

Events

Draw [Data: { style:String, type:"DOM", co}]
when the entity is ready to be drawn to the stage

public this .DOM(HTMLElement elem)

elem
HTML element that will replace the dynamically created one

Pass a DOM element to use rather than one created. Will set ._element to this value. Removes the old element.

Back to top

.draw

public this .draw([[Context ctx, ]Number x, Number y, Number w, Number h])

ctx
Canvas 2D context if drawing on another canvas is required
x
X offset for drawing a segment
y
Y offset for drawing a segment
w
Width of the segment to draw
h
Height of the segment to draw

Method to draw the entity on the canvas element. Can pass rect values for redrawing a segment of the entity.

Back to top

.undraw

public this .undraw(void)

Removes the element from the stage.

Back to top

.css

public * css(String property, String value)

property
CSS property to modify
value
Value to give the CSS property

public * css(Object map)

map
Object where the key is the CSS property and the value is CSS value

Apply CSS styles to the element.

Can pass an object where the key is the style property and the value is style value.

For setting one style, simply pass the style as the first argument and the value as the second.

The notation can be CSS or JS (e.g. text-align or textAlign).

To return a value, pass the property.

Note: For entities with "Text" component, some css properties are controlled by separate functions .textFont() and .textColor(), and ignore .css() settings. See Text component for details.

Example

this.css({'text-align', 'center', 'text-decoration': 'line-through'});
this.css("textAlign", "center");
this.css("text-align"); //returns center