Konva拖放下落而不移动拖动元素 [英] Konva drag drop without moving drag element

查看:205
本文介绍了Konva拖放下落而不移动拖动元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是如何拖放形状,但是要克隆可拖动的形状,然后将该克隆拖动到可放置的形状。

My question is how to drag and drop a shape, but with cloning the draggable shape, and dragging that clone to the droppable shape.

我是Konva的新手。在查看文档和文档时,我可以找到如何拖放形状的示例。

I am new to Konva. While looking around the documentation & examples I could find how to drag and drop a shape.

我找到了克隆形状的参考,但是我不确定如何做到这一点。

I found reference to cloning of the shape, but I am not sure how to do this.

如果有人可以向我展示这种方式,将不胜感激。

If someone could show me the way that would be very much appreciated.

谢谢

推荐答案

rect.on('dragstart', function() {
    // stop dragging original rect
    rect.stopDrag();

    // clone it
    var clone = rect.clone({
        x : 50,
        y : 50
    });
    // events will also be cloned
    // so we need to disable dragstart
    clone.off('dragstart');

    // then add to layer and start dragging new shape
    layer.add(clone);
    clone.startDrag();
});

http://jsbin.com/hujulasaro/1/edit?html,js,output

事件请参见演示: http://konvajs.github.io/docs/drag_and_drop/Drop_Events.html

这篇关于Konva拖放下落而不移动拖动元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆