slash197
slash197

Reputation: 9034

Style SVG elements with Bonsai JS

Just started using Bonsai JS and can't find anything in the docs so I thought I ask here. How can I set an elements class attribute so I can define some styles in CSS? Most of the styles are supported directly in Bonsai but I would also need to change the cursor type on hover over an element.

Upvotes: 0

Views: 188

Answers (1)

basecode
basecode

Reputation: 1510

BonsaiJS doesn't let you set a "class" attribute. Instead you add a listener when the curser hovers over a DisplayObject.

new Rect(150, 150, 150, 150).attr({
  fillColor: "red"
}).addTo(stage).on("mouseover mouseout", function(e) {
  this.attr({
    cursor: e.type == "mouseover" ? "pointer" : "inherit"
  });
});

Open in Orbit: http://orbit.bonsaijs.org/#new%20Rect(150%2C%20150%2C%20150%2C%20150).attr(%7B%0A%20%20fillColor%3A%20%22red%22%0A%7D).addTo(stage).on(%22mouseover%20mouseout%22%2C%20function(e)%20%7B%0A%20%20this.attr(%7B%0A%20%20%20%20cursor%3A%20e.type%20%3D%3D%20%22mouseover%22%20%3F%20%22pointer%22%20%3A%20%22inherit%22%0A%20%20%7D)%3B%0A%7D)%3B%0A%20

Upvotes: 0

Related Questions