使用拖动和调整大小的jsPlumb问题

使用拖动和调整大小的jsPlumb问题

本文介绍了使用拖动和调整大小的jsPlumb问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在项目中使用jsPlumb,基本上是建立流程图,用户可以在其中将形状从一个div拖放到另一个div(#frame).

I'm using jsPlumb in my project that, basically, build a flowchart, where user can drag and drop a shape from one div to another (#frame).

所以我希望某些形状可以调整大小,但是我遇到了一些问题,因为当我尝试调整形状大小时,它也会像拖动一样移动.

So I want that some shapes are resizable, but I'm having some problems, because when I try to resize the shape, it moves like I was dragging too.

我在resize事件中使用了jsPlumb.repaint,但还是一团糟.

I used the jsPlumb.repaint at the resize event, but still messed.

/**
 * Enable element to be resizable at the div '#frame'.
 * Set a new ID to the element
 *
 * @param {Object} elem
 */
function make_resizable(elem) {
    count_id++;

    var id_name = "production_" + count_id; // build a new id
    elem.attr("id", id_name);

    $("#frame").append(elem);

    elem.resizable({
        resize: function(event, ui) {
          jsPlumb.repaint(ui.helper);
        },
        handles: "all"
    });

    jsPlumb.draggable(elem, {
        containment: "parent"
    });
}

function make_draggable(elem) {
    elem.removeClass("drag").addClass("draggable onFrame");

    elem.attr("visible", "true");
    elem.draggable({
        containment: 'parent',
    });
}

$(document).ready(function(){
    $(".drag").draggable({
        revert: "invalid",
        helper: 'clone',
        cursor: "move",
        containment: 'frame'
    });

    $("#frame").droppable({
        accept: ".drag",
        drop: function(event, ui) {
            var cloned = $(ui.helper).clone();

            if ( $(ui.helper).parent("#frame").length == 0 ) {
                var pos = $(ui.helper).offset();
                var draggableOffset = ui.helper.offset(),
                    droppableOffset = $(this).offset(),
                    left = draggableOffset.left - droppableOffset.left,
                    thisTop = draggableOffset.top - droppableOffset.top;

                cloned.css({
                    "left": left,
                    "top": thisTop
                });

                if ( cloned.hasClass("production-unit")) {
                    make_resizable(cloned);
                    //cloned.css("z-index", zIndex_unit++);
                } else {
                    make_connectable(cloned);
                    //cloned.css("z-index", zIndex_elem++);
                }

                make_draggable(cloned);
            }
        }
    });
});

推荐答案

对于较新版本的JsPlumb,该错误仍然存​​在.在这种情况下,只需在拖动选项中使用过滤器选项即可.

For the newer versions of JsPlumb the bug persists. In this case, just use the filter option in the drag options.

instance.draggable((element), {
   filter: ".ui-resizable-handle"
});

https://github.com/jsplumb/katavorio/wiki#filtering

这篇关于使用拖动和调整大小的jsPlumb问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 07:01