当鼠标左键和右键同时单击并拖动时,我可以设置舞台的可拖动事件吗?
问问题
110 次
1 回答
2
如果您想在按下左右按钮之前阻止拖动,您可以设置形状的 dragBoundFunc 以限制所有拖动,直到您说可以拖动(当您看到两个按钮都按下时)
这是一个关于 dragBoundFunc 的链接:
以下是一些入门代码:
// add properties to tell whether left/right buttons are currently down
myShape.leftIsDown=false;
myShape.rightIsDown=false;
// add mousedown to set the appropriate button flag to true
myShape.on("mousedown",function(event){
if(event.button==0){this.leftIsDown=true;}
if(event.button==2){this.rightIsDown=true;}
});
// add mouseup to set the appropriate button flag to false
myShape.on("mouseup",function(event){
if(event.button==0){this.leftIsDown=false;}
if(event.button==2){this.rightIsDown=false;}
});
// add a dragBoundFunc to the shape
// If both buttons are pressed, allow dragging
// If both buttons are not pressed, prevent dragging
dragBoundFunc: function(pos) {
if(this.leftIsDown && this.rightIsDown){
// both buttons are down, ok to drag
return { pos }
}else{
// both buttons aren't down, refuse to drag
return {
x: this.getAbsolutePosition().x,
y: this.getAbsolutePosition().y
}
}
}
于 2013-11-06T04:51:11.477 回答