如何在鼠标单击时设置可拖动事件
How to set the draggable event on mouse click?
我可以设置同时单击和拖动鼠标左键和右键时阶段的可拖动事件吗?
如果要在按下左右按钮之前阻止拖动,则可以设置形状的dragBoundFunc以限制所有拖动,直到您说可以拖动为止(当您看到两个按钮都向下时)
这里有一个关于dragBoundFunc的链接:
http://www.html5canvastutorials.com/kineticjs/html5-canvas-drag-and-drop-shapes-horizontally-or-vertically-tutorial/
下面是一些入门代码:
// 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
}
}
}
相关文章:
- 无法为HTML5中具有画布和图像的可拖动元素设置“拖动图像”
- JQuery UI可拖动:如果助手设置为克隆,为什么不't可拖动集的已应用类到克隆
- 拖动时设置滚动条不透明度
- 谷歌地图:想在设置draggable为true后直接拖动地图
- HTML元素的光标是在拖动之后设置的,但不是在拖动过程中设置的
- 获取图像可见区域状态,以在画布中将图像设置在先前拖动的位置
- 如何将宽度和高度设置为可拖动图像
- 如何在鼠标单击时设置可拖动事件
- 在 SpannableString 上设置拖动侦听器
- 通过可拖动的 SVG 形状设置 HTML 输入值 ?(或画布)
- 设置下降效果和效果允许在拖动启动不会立即生效
- 从画布 html5 中上传的图像中删除拖动属性(将区域设置为上传的图像)
- 在传单地图上设置并拖动标记可更新表单输入字段,而无需发送
- 根据拖动方向设置轴jQuery拖动
- 设置可拖动对象的左上角位置
- 拖动&将自定义HTML拖放设置为拖动图像
- Jquery-如何设置溢出以滚动具有多个可丢弃项的可拖动项
- 设置拖动事件的起始位置
- 如何在d3 JavaScript库中设置拖动行为的原点(drag. Origin)
- html 拖放设置拖动图像在第一次拖动时不会设置重影图像