Han*_*com 0 javascript html5 canvas kineticjs
我有以下例子来创建一个多边形:
var poly = new Kinetic.Polygon({
x: coorx,
y: coory,
points: coords,
alpha: 0,
fill: colors[Math.floor(Math.random() * colors.length)],
name: myname
});
Run Code Online (Sandbox Code Playgroud)
我想要做的是有两个类名,例如"rect-1"和"rect-2".我希望其中一些形状具有其中一个类,一些将同时具有这两个类.
这一点的关键是能够使用get()语法以一种方式转换某些形状,例如以不透明度转换,以及以其他方式转换其他形状,例如:
是否可以为高级选择赋予形状多个"类"名称,如我在此描述的那样?
谢谢!
var shapes = stage.get(".rect-1");
for(var n = 0; n < shapes.length; n++) {
var shape = shapes[n];
shape.transitionTo({
alpha: (opacities[Math.floor(Math.random() * opacities.length)] * 1.5) + .7,
duration: 2
});
}
var shapes = stage.get(".rect-2");
for(var n = 0; n < shapes.length; n++) {
var shape = shapes[n];
shape.transitionTo({
offset: {
x: 10,
y: 10
},
duration: 2
});
}
Run Code Online (Sandbox Code Playgroud)
有趣的用例!我将这个添加到我的待办事项列表中.也许是这样的:
var rect = new Kinetic.Rect({
name: 'foo bar test'
});
Run Code Online (Sandbox Code Playgroud)
将分配三个不同的名称(类似于DOM类名称字符串)