KineticJS drag a box with line connected

我只是一个虾纸丫 提交于 2019-12-02 04:12:40

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!