[英]JointJS - Mouse click event triggers cell position change event
I need to define mouse click event for my each cell. 我需要为每个单元格定义鼠标单击事件 。 I used
cell:pointerup
event; 我使用了
cell:pointerup
事件; but this event is triggered when I change positions of cells too. 但是当我也更改单元格的位置时会触发此事件。 How can I differentiate these 2 events?
如何区分这两个事件?
Thanks in advance. 提前致谢。
What you can do is to create a custom element view and distinct click from dragging by checking whether a pointermove
event was triggered between pointerdown
and pointerup
events. 您可以做的是创建一个自定义元素视图,并通过检查是否在
pointerdown
和pointerup
事件之间触发了pointermove
事件来从拖动中获得明显的点击。
var ClickableView = joint.dia.ElementView.extend({
pointerdown: function () {
this._click = true;
joint.dia.ElementView.prototype.pointerdown.apply(this, arguments);
},
pointermove: function () {
this._click = false;
joint.dia.ElementView.prototype.pointermove.apply(this, arguments);
},
pointerup: function (evt, x, y) {
if (this._click) {
// triggers an event on the paper and the element itself
this.notify('cell:click', evt, x, y);
} else {
joint.dia.ElementView.prototype.pointerup.apply(this, arguments);
}
}
});
And then tell the joint.dia.Paper
to use the view. 然后告诉
joint.dia.Paper
使用该视图。
var paper = new joint.dia.Paper({
// el, width, height etc.
elementView: ClickableView
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.