[英]How do I add a class to a Rect in bonsaijs?
I need to add a class to a Rect. 我需要向Rect添加一个类。 I can't seem to figure out how to do it.
我似乎不知道该怎么做。
bar = (new Rect(x, ySegment * 10 + 30 + margin, w, 0)
.attr('opacity', 0.8)
.attr('class', data[i].segments[j].color)
.addTo(stage));
the class attr
is ignored. 类
attr
被忽略。
A DisplayObject
like Rect
isn't the representation of an HTMLElement. 像
Rect
这样的DisplayObject
并不是HTMLElement的表示。 That's why custom attributes like "class" don't work. 这就是为什么自定义属性(例如“类”)不起作用的原因。 If your intention is to re-use attributes for different DisplayObjects, then try the following:
如果您打算为不同的DisplayObject重新使用属性,请尝试以下操作:
var myAttrs = {
fillColor: 'red',
opacity: 0.5
};
new Rect(20, 20, 100, 100).attr(myAttrs).addTo(stage);
new Rect(20, 130, 100, 100).attr(myAttrs).addTo(stage);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.