【问题标题】:Using custom context menu for cytoscape.js nodes为 cytoscape.js 节点使用自定义上下文菜单
【发布时间】:2017-12-01 19:17:32
【问题描述】:

我正在尝试使用this context menu javascript library,但似乎无法在右键单击节点时触发它。

我尝试实现基本的演示并且效果很好,所以我在页面上有了必要的 js。

我将它添加到节点的左键单击并尝试通过custom方式触发上下文菜单,如下所示:

graph.$('node').on('cxttapstart', function (event) {

            event.cyTarget.contextMenu();
        });

$.contextMenu({
        selector: '.context-menu-one',
        trigger: 'none',
        callback: function (key, options) {
            var m = "clicked: " + key;
            window.console && console.log(m) || alert(m);
        },
        items: {
            "edit": { name: "Edit", icon: "edit" },
            "cut": { name: "Cut", icon: "cut" },
            "copy": { name: "Copy", icon: "copy" },
            "paste": { name: "Paste", icon: "paste" },
            "delete": { name: "Delete", icon: "delete" },
            "sep1": "---------",
            "quit": { name: "Quit", icon: function ($element, key, item) { return 'context-menu-icon context-menu-icon-quit'; } }
        }
    });

但我就是不知道在网上做什么

selector: '.context-menu-one'

以便上下文菜单显示在节点旁边。

以前有人做过吗?

干杯

【问题讨论】:

    标签: javascript jquery cytoscape.js jquery-context


    【解决方案1】:

    event.cyTarget (2.x) 或 event.target (3.x) 不是 dom 元素。这是一个细胞景观元素。您需要为菜单创建自己的 dom 元素(例如 div)并将其相对于 node.renderedPosition() 定位在 cxttap 上。

    如果您想在 cytoscape 中使用上下文菜单,只需使用现有的扩展程序会更容易。

    有一个现代的圆形滑动菜单:https://github.com/cytoscape/cytoscape.js-cxtmenu

    还有一个是传统的列表菜单:https://github.com/iVis-at-Bilkent/cytoscape.js-context-menus

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多