【问题标题】:JointJS - Mouse click event triggers cell position change eventJointJS - 鼠标点击事件触发单元格位置改变事件
【发布时间】:2013-12-15 16:48:03
【问题描述】:

我需要为每个单元格定义鼠标点击事件。我使用了cell:pointerup 事件;但是当我也更改单元格的位置时会触发此事件。如何区分这 2 个事件?

提前致谢。

【问题讨论】:

    标签: javascript svg jquery-svg jointjs


    【解决方案1】:

    您可以做的是创建一个自定义元素视图,并通过检查是否在pointerdownpointerup 事件之间触发了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);
        }
      }
    });
    

    然后告诉joint.dia.Paper 使用视图。

    var paper = new joint.dia.Paper({
      // el, width, height etc.
      elementView: ClickableView
    });
    

    可以在here找到一个小提琴。

    【讨论】:

    • 非常感谢@Roman 的帮助;它就像一个魅力!
    • 如果我只想将此视图应用于某个模型,而不是纸上的所有内容,该怎么办?我应该如何进行?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-07
    相关资源
    最近更新 更多