Extend jsplumb.draggable drag behavior

。_饼干妹妹 提交于 2019-12-01 18:32:15

jsPlumb.draggable helps to update the DOM element whenever it is dragged. Instead you can write that code in jQuery draggable as:

$('#dragcodes').draggable(
{
    drag: function(){
    jsPlumb.repaint($(this)); // (or) jsPlumb.repaintEverything(); to repaint the connections and endpoints
    //followed by your code
    var offset = $(this).offset();
    var xPos = offset.left;
    var yPos = offset.top;
    console.log('x: ' + xPos);
    console.log('y: ' + yPos);
}
});

Now there is no need for jsPlumb.draggable($(".dragcodes"));

In Version 1.6.3 the following Code works:

jsPlumb.draggable("#dragcodes", {
  drag: function (event, ui) { //gets called on every drag
    console.log(ui.position);  //ui.position.left and ui.position.top
  }
);

The best approach is to configure DragOptions of jsPlumb.Defaults. You have to specify drag function:

jsPlumb.getInstance({
....,
DragOptions: {
  drag: function() {
  }
},
....
);

JsPlumb Version 2.1.4

jsPlumb.draggable("#yourElement", {
  drag: function (event) {
    console.log(event.pos[0]); // for left position
    console.log(event.pos[1]); // for top position
  }
);

Or

jsPlumb.draggable("#yourElement", {
  drag: function (event) {
    $(event.el).position().left; // for left position
    $(event.el).position().top; // for top position
  }
);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!