D3和SVG中的自定义上下文菜单 [英] Custom context menu in d3 and svg

查看:435
本文介绍了D3和SVG中的自定义上下文菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我右键单击一个svg圆圈时,我希望显示自定义上下文菜单. 现在,我已经找到了答案,该答案可以帮助我使用以下代码来处理右键单击:

I would like to have custom context menu appearing when I right click on an svg circle. For now I have found this answer that helps me to handle the right click with the following code:

.on("contextmenu", function(data, index) {
   //handle right click

   //stop showing browser menu
   d3.event.preventDefault()
});

现在我想知道如何显示一个包含HTML的框.

Now I would like to know how I can show a box containing some HTML.

谢谢.

推荐答案

d3.select('#stock_details .sym').on("contextmenu", function(data, index) {
    var position = d3.mouse(this);
    d3.select('#my_custom_menu')
      .style('position', 'absolute')
      .style('left', position[0] + "px")
      .style('top', position[1] + "px")
      .style('display', 'block');

    d3.event.preventDefault();
});

这篇关于D3和SVG中的自定义上下文菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆