【问题标题】:Kineticjs Groups of shapes can be dragged out of stage and mousedown outside stage, loses the shapesKineticjs 形状组可以拖出舞台并在舞台外鼠标按下,失去形状
【发布时间】:2013-11-06 03:51:40
【问题描述】:

Kineticjs 可以将形状组拖出舞台,舞台外的 mousedown 会丢失形状。

【问题讨论】:

    标签: html kineticjs


    【解决方案1】:

    是的……

    默认情况下,形状可以拖出组,甚至拖出舞台。

    您可以使用 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
        }
      }
    });
    

    【讨论】:

    猜你喜欢
    • 2012-09-30
    • 2013-09-14
    • 2013-10-26
    • 2014-08-29
    • 2018-05-05
    • 1970-01-01
    • 2013-05-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多