【问题标题】:Present custom menu on right click Plotly.js在右键单击 Plotly.js 时显示自定义菜单
【发布时间】:2017-12-02 19:50:20
【问题描述】:

是否可以在用户右键单击绘图时显示自定义子菜单,而不是默认子菜单?

【问题讨论】:

    标签: javascript plotly


    【解决方案1】:

    您可以将事件添加到 contextmenu plotly 容器。

    这是对contextmenu 文档的引用 - https://developer.mozilla.org/en/docs/Web/Events/contextmenu

    您将阻止上下文菜单的默认行为,以使浏览器的默认上下文菜单不会与您的重叠。

    你可以用这个

    document.querySelector('#plotly-container').addEventListender('contextmenu', function(event) {
        event.preventDefault();
    
        // Your code here
    });
    

    在回调函数中,您需要用event.clientXevent.clientY 识别鼠标位置,并将容器绝对定位在这些坐标上。

    您可以参考这个问题来了解如何在鼠标位置旁边创建一个 div 容器。

    How do I position a div next to a mouse click using JQuery?

    你可以参考这个问题来了解更多关于如何绑定contextmenu事件。

    How can I capture the right-click event in JavaScript?

    【讨论】:

    • 我会尽快尝试。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-21
    • 1970-01-01
    • 1970-01-01
    • 2019-05-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多