Core.prototype.setStyle()

The setStyle() method sets visual styles of graphic elements. By default, it applies to the front and back layers.

Visual styles are applied to all child elements immediately below the layer at once. Visual styles that are invalid for that child element are ignored, even if they are set.

Syntax

setStyle(style)
setStyle(style, layer)

Parameters

style
An object that contains visual styles.
layer (Optional)
A drawing layer or an array of drawing layers to apply visual styles to.
If this argument is omitted, visual styles will be applied to Core.prototype.front and Core.prototype.back.

Return value

none

Visual styles

An object with the following properties. All properties are optional and only those specified apply.

fill
The color that fills the background of graphic elements. The initial value of the default element is white.
stroke
The color of lines and outlines of graphic elements. The initial value of the default element is black.
stroke-width
Width of lines and outlines of graphic elements. The initial value of the default element is 1. You can pass the return value of BasicCreator.prototype.getWidth() as is.

In addition to these, you can set attributes available on the <svg> graphic elements.

Examples

const core = new jmotion.Core("#board");
const style = {
    "stroke": "blue",
    "stroke-width": 3,
};
core.setStyle(style);