【发布时间】:2013-03-07 02:19:12
【问题描述】:
我添加了 10 个可拖动的矩形,我希望能够在它们被一一点击时将它们移除。现在它只删除第一个,然后不再删除。是否可以向矩形 ID 添加点击事件?
var stage = new Kinetic.Stage({
container: 'container',
width: 578,
height: 400
});
var layer = new Kinetic.Layer();
for (var i = 0; i< 10; i++) {
var rect = new Kinetic.Rect({
x: 239 + (i *3),
y: 75 + (i * 3),
width: 100,
height: 50,
fill: 'blue',
stroke: 'black',
strokeWidth: 4,
draggable: true,
id: i
});
rect.on('click', function() {
rect.hide();
});
// add the shape to the layer
layer.add(rect);
// add the layer to the stage
stage.add(layer);
}
【问题讨论】:
标签: kineticjs