简体   繁体   English

拖动开始事件的draw2d

[英]draw2d on drag start event

I want to call my custom callback function every time, when user starts dragging figures. 我想在每次用户开始拖动数字时调用我的自定义回调函数。 I tried to do it like so: 我试着这样做:

figure.onDragStart = function (x, y, shiftKey, ctrlKey) {
    myfunc();
};

But the problem is, every time when my function is called, figure is positioned to 0,0 coordinate. 但问题是,每次调用我的函数时,数字都会定位到0,0坐标。 I'm not sure what is wrong with that and how can I fix it. 我不确定这有什么问题,我该如何解决它。

Instead of redefining the onDragStart method, you can handle the dragstart event: 您可以处理dragstart事件,而不是重新定义onDragStart方法:

figure.on("dragstart", function(event, ui) {
    // Do something
});

According to the draw2d documentation , that event is triggered by onDragStart . 根据draw2d文档 ,该事件由onDragStart触发。 The ui parameter contains x , y , shiftKey and ctrlKey . ui参数包含xyshiftKeyctrlKey

You can see the code in action in this jsfiddle . 你可以在这个jsfiddle中看到代码。 A message is displayed in the console when you start dragging a rectangle. 开始拖动矩形时,控制台中会显示一条消息。 The green rectangle uses the dragstart event and responds correctly. 绿色矩形使用dragstart事件并正确响应。 The red one redefines the onDragStart method, with the problem mentioned in your question. 红色的方法重新定义了onDragStart方法,问题中提到了问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM