KineticJS drag a box with line connected

后端 未结 1 1808
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-25 02:24

I\'ve seen an example of this done on the web before, but I cannot find the link anymore.

Basically it is a KineticJS example of a draggable box, with lines connected t

1条回答
  •  盖世英雄少女心
    2021-01-25 02:57

    It's not too difficult to do...

    Create your box:

     var box = new Kinetic.Rect({x:10,y:10, other stuff });
    

    create your line:

     var line = new Kinetic.Line({ x: box.getX(), y: box.getY(), other stuff });
     var originalPoint = {x: box.getX(), y: box.getY()}; // save original box coordinates
    

    then add a drag event redefine the line

     box.on('dragstart dragmove', function(){
         line.setPoints([originalPoint.x, originalPoint.y, box.getX(), box.getY() ]);
         layer.draw();  //redraw current layer
     });
    

    like so: http://jsfiddle.net/KS9Bf/3/

    This is exactly what you were asking about: http://jsfiddle.net/KS9Bf/6/

    Its an update to the previous one.

    0 讨论(0)
提交回复
热议问题