Как установить перетаскиваемое событие по щелчку мыши?
Могу ли я установить перетаскиваемое событие сцены, когда левая и правая кнопки мыши нажаты и перетащены одновременно.
1 ответ
Решение
Если вы хотите предотвратить перетаскивание до тех пор, пока не будут нажаты обе кнопки: левая и правая, вы можете установить 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
}
}
}