【问题标题】:Prevent dragging in Joint JS防止在联合 JS 中拖动
【发布时间】:2014-05-27 09:22:52
【问题描述】:

我正在研究 JointJS API。但是我想防止元素从它们的原始位置移动。您能否建议我使用 JointJS 的一些功能或一般的 CSS 的任何功能,我可以使用它们来使我的对象不可移动。

我不能在纸上使用 interactive: false optionpaper.$el.css('pointer-events', 'none'); 因为我当鼠标悬停在元素上时需要具有突出显示功能。

请提出一种在允许其他功能的同时禁止元素移动的方法。相关CSS代码sn-p如下:

.viewport {
    -webkit-user-select: none;
    -moz-user-select: none;
    user-select: none;
}
.element {
    /* Give the user a hint that he can drag&drop the element. */
    cursor: crosshair;
    position: fixed;
}
.element * {
    /* The default behavior when scaling an element is not to scale the stroke in order to prevent the ugly effect of stroke with different proportions. */
    vector-effect: non-scaling-stroke;
    -moz-user-select: none;
    user-drag: none;
    position: fixed;
}

【问题讨论】:

  • 你能告诉我们一些你尝试过的东西,或者一些示例代码吗?
  • 嘿,我已经编辑了这个问题。请看一下:)
  • 嗨,您有没有找到解决问题的方法?

标签: css jointjs


【解决方案1】:

interactive 选项还允许function 值。要只允许与链接交互(更具体地说是joint.dia.LinkView 实例),您可以这样做:

var paper = new joint.dia.Paper({
  el: $('#paper'),
  width: 400,
  height: 400,
  model: graph,
  interactive: function(cellView, method) {
    return cellView instanceof joint.dia.LinkView; // Only allow interaction with joint.dia.LinkView instances.
  }
});

或者,您可以检查method 参数。尝试拖动元素时method 的值为pointermove,单击链接时为pointerdown

我希望这会有所帮助!

【讨论】:

  • 不幸的是,基于我的使用,由于某种原因,上面的方法参数永远不会等于 pointermove。
  • 方法参数对我来说是未定义的。有其他选择吗?
【解决方案2】:

对我有用的解决方案是将以下内容添加到 Paper 定义中:

interactive: function(cellView) {
  if (cellView.model.get('locked')) {
    return {
      elementMove: false
    };
  }
  // otherwise
  return true;
}

然后在我想锁定的元素上(防止移动),我添加了:

element.set('locked', true);

【讨论】:

    【解决方案3】:
    var paper = new joint.dia.Paper({
      el: $('#paper'),
      width: 400,
      height: 400,
      gridSize: 10,
      model: graph,
      interactive: false // <------
    });
    

    【讨论】:

    • OP 似乎表明interactive 属性不是一个选项。
    • jointjs.com/api -> interactive - 如果设置为 false,则禁用与元素和链接的交互。如果它是一个函数,它将在单元格视图中调用,并在其中评估它的方法的名称('pointerdown','pointermove',...)。如果此类函数的返回值为 false,则该操作将禁用交互。对于链接,交互对象的特殊属性可用于禁用默认行为。这些属性是:vertexAdd、vertexMove、vertexRemove 和 arrowheadMove。通过设置 ...
    猜你喜欢
    • 1970-01-01
    • 2011-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-02
    • 2011-12-12
    • 2021-11-01
    相关资源
    最近更新 更多