css - 仅在联合js中使链接具有交互性

标签 css jointjs

我得到了这个带有一些矩形和链接的联合 js 代码:

var graph = new joint.dia.Graph;
var paper = new joint.dia.Paper({
    el: $('#div1'),
    interactive: false,
    width: 1200,
    height: 1200,
    model: graph,
    gridSize: 1
});
    var rect1 = new joint.shapes.basic.Rect({
        position: { x: 80, y: y_value },
        size: { width: 30, height: 55 },
        attrs: { 
            rect: { fill: bgcolor1,'stroke-width': 0 },
            text: {
                text: 'Rect1',
                fill: 'white'
            } 
        }
    });

    var rect2 = new joint.shapes.basic.Rect({
        position: { x: 80, y: y_value + 80 },
        size: { width: 30, height: 55 },
        attrs: { 
            rect: { fill: bgcolor1,'stroke-width': 0 },
            text: {
                text: 'Rect1',
                fill: 'white'
            } 
        }
    });

    var link{{ pre }} = new joint.dia.Link({
        source: { id: rect1.id },
        target: { id: rect2.id },
        vertices: [{ x: initialx, y: syposition.y + 23 }, { x: initialx, y: typosition.y + 23 }],
    });     

如您所见,我将 paper 属性设置为“false”,因此用户不能拖放任何元素或删除链接,但实际上他希望他可以随意拖动链接顶点,我该怎么做它?, joint.min.css 中的属性?或者从这段代码那里有办法吗??

提前致谢!

最佳答案

首先,您可以将 interactive 定义为一个函数,它为链接返回 true,为元素返回 false。这使得链接具有交互性,而元素则没有。

var paper = new joint.dia.Paper({
  interactive: function(cellView) {
    return cellView.model.isLink();
  }
});

根据文档

interactive - if set to false, interaction with elements and links is disabled. If it is a function, it will be called with the cell view in action and the name of the method it is evaluated in ('pointerdown', 'pointermove', ...). If the returned value of such a function is false interaction will be disabled for the action. For links, there are special properties of the interaction object that are useful to disable the default behaviour. These properties are: vertexAdd, vertexMove, vertexRemove and arrowheadMove. By setting any of these properties to false, you can disable the related default action on links.

通过执行以下操作,您可以仅启用顶点移动。

interactive: function(cellView) {
  if (cellView.model.isLink()) {
    return {
      vertexAdd: false,
      vertexRemove: false,
      arrowheadMove: false,
      // vertexMove: true
    }
  }
  return false;
}

http://jsfiddle.net/kumilingus/03omcuLm/

关于css - 仅在联合js中使链接具有交互性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37192811/

相关文章:

javascript - JointJS 版本 3 中的命名空间问题

html - `justify-content` 属性不适用于嵌套的 flexbox

css - HTML/CSS 字体 : Different browsers/OSs different results

javascript - 我可以在 jointjs 元素中添加新属性吗?

javascript - JointJs - onConnect 链接事件

javascript - Hello World 不能在带有 jointjs 的 html 中正常工作?

Jointjs 拖动链接目标时,让它调用自定义函数

ios - 如何在mobile safari和ios模拟器中调试?

html - 通过CSS模糊图像的边框

css - 突出显示 JavaFx 标签中的文本