【发布时间】:2013-11-06 03:51:40
【问题描述】:
Kineticjs 可以将形状组拖出舞台,舞台外的 mousedown 会丢失形状。
【问题讨论】:
Kineticjs 可以将形状组拖出舞台,舞台外的 mousedown 会丢失形状。
【问题讨论】:
是的……
默认情况下,形状可以拖出组,甚至拖出舞台。
您可以使用 dragBoundFunc 将形状拖动到指定区域。
这是一个小提琴:http://jsfiddle.net/m1erickson/bP92U/
var rect = new Kinetic.Rect({
x: 20,
y: 20,
width:50,
height:30,
fill: 'blue',
draggable: true,
dragBoundFunc: function(pos) {
var w=this.getWidth();
var h=this.getHeight();
if(pos.x<0){pos.x=0;}
if(pos.x+w>sw){pos.x=sw-w;}
if(pos.y<0){pos.y=0;}
if(pos.y+h>sh){pos.y=sh-h;}
return {
x: pos.x,
y: pos.y
}
}
});
【讨论】: