tal*_*a06 0 javascript svg jquery-svg jointjs
我需要为每个单元格定义鼠标单击事件.我用cell:pointerup
事件; 但是当我改变细胞位置时会触发此事件.我如何区分这两个事件?
提前致谢.
你可以做的是创建一个自定义元素视图通过检查是否拖动和独特的点击pointermove
事件被触发之间pointerdown
和pointerup
事件.
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);
}
}
});
Run Code Online (Sandbox Code Playgroud)
然后告诉joint.dia.Paper
使用视图.
var paper = new joint.dia.Paper({
// el, width, height etc.
elementView: ClickableView
});
Run Code Online (Sandbox Code Playgroud)
可以在这里找到一个小提琴.