【发布时间】:2015-07-31 21:36:28
【问题描述】:
我在我的项目中使用 jsPlumb,基本上,它构建了一个流程图,用户可以在其中将形状从一个 div 拖放到另一个 (#frame)。
所以我希望某些形状可以调整大小,但我遇到了一些问题,因为当我尝试调整形状大小时,它的移动就像我在拖动一样。
我在 resize 事件中使用了 jsPlumb.repaint,但还是一团糟。
/**
* 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);
}
}
});
});
【问题讨论】:
-
我刚刚删除了 make_resizable 的 jsPlumb.draggable() 并开始工作了!
-
请发表您的评论作为答案并接受它。
标签: jquery drag-and-drop resize jsplumb