0

我有两个重叠的形状,当我单击重叠时我想拖动两者。是否有捷径可寻?

4

1 回答 1

0

http://jsfiddle.net/JPeJF/1/

这是一个小错误,但你可以修饰它,它可以满足你的要求,只需要更多的逻辑/抛光。

您需要查看的主要代码是:

  shapesLayer.on('mousedown', function(){
     var userPos = stage.getUserPosition();
     var intersected = shapesLayer.getIntersections(userPos); //gets all shapes intersecting at click position
     for(var i = 0; i < intersected.length; i++) {
       intersected[i].moveTo(group2);   // moves intersected shapes to a new group , need to add some code so that when item is moved to new group it keeps it's position
     }
     group2.simulate('dragstart'); //simulate dragging
     shapesLayer.draw();
  });

  shapesLayer.on('mouseup', function(){  //when mouse is released
    var kids = group2.getChildren();
     for(var i = 0; i < kids.length; i++) {
       kids[i].moveTo(shapesLayer);      //place back in original container
     }
    shapesLayer.draw();
  });
于 2013-02-12T15:12:55.210 回答