Two.js: Custom attributes

Created on 10 Feb 2016  路  2Comments  路  Source: jonobr1/two.js

I imagine there's a way to do this, but I can't find it for the life of me.

I want to add my own attributes to the rendered objects. For example, if I'm rendering an SVG, to add stroke-dasharray as an attribute.

There's nothing about it in the docs, the closest thing I came across wasmanualas a last parameter inPath, but this isn't available inPolygon` for me to try.

question

Most helpful comment

You sure can! Here it is:

var path = two.makePath(...);
two.update(); // You have to force the renderer to update so the element will be created.
var elem = path._renderer.elem; // The SVG Element
elem.setAttribute('custom-attr', customValue);

Hope that makes sense!

All 2 comments

You sure can! Here it is:

var path = two.makePath(...);
two.update(); // You have to force the renderer to update so the element will be created.
var elem = path._renderer.elem; // The SVG Element
elem.setAttribute('custom-attr', customValue);

Hope that makes sense!

Ah, wonderful. Thank you very much.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sami8github picture sami8github  路  3Comments

davidwebca picture davidwebca  路  5Comments

trusktr picture trusktr  路  8Comments

Neglexis picture Neglexis  路  7Comments

anderspitman picture anderspitman  路  4Comments