javascript - 将事件从覆盖的 div 传递到 Highmaps

标签 javascript highcharts highmaps

我正在使用 Highmaps 来显示一个简单的 map ,在它上面我有另一个 div,其中有一个组件可以在 map 顶部绘制内容(必须以这种方式完成,不幸的是,我无法在 Highmaps 中绘制所有内容)。

现在我想与 map 进行一些交互,尽管它位于我的 div 下方。我想知道当我点击 map 上的div时是否有办法触发 map 上的点击、悬停等事件。

我搜索过Highmaps docs试图找到类似 a 的方法 trigger(ev, x, y) 但似乎没有。然后我尝试使用 MouseEvent() 纯javascript解决方案和 Map DOM 上的 dispatchEvent(),但它也不起作用。

我已经设置了一个简单的 fiddle 来完成我想要的工作:http://jsfiddle.net/k11yfz58/1/

如果我们注释 #overlay div,当我们单击某个状态时,我们会收到警报。我想要相同的行为,但是单击覆盖 div,这可能吗?

谢谢!

编辑

建议为此使用 pointer-events CSS 属性。这并不能解决我的问题,因为我还需要在 #overlay div 上触发事件。

最佳答案

您可以将其添加到您的 CSS 中:

#overlay {
    pointer-events: none;
}

来自MDN :

The pointer-events CSS property specifies under what circumstances (if any) a particular graphic element can become the target of mouse events.

none值:

none
The element is never the target of mouse events; however, mouse events may target its descendant elements if those descendants have pointer-events set to some other value. In these circumstances, mouse events will trigger event listeners on this parent element as appropriate on their way to/from the descendant during the event capture/bubble phases.

这意味着您的覆盖元素对鼠标事件“不可见”,因此鼠标事件发生在下面的 div 上。

关于javascript - 将事件从覆盖的 div 传递到 Highmaps,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49153758/

相关文章:

javascript - Wordpress:http 网站在 chrome 中通过 https 加载 css 和 js 文件

javascript - 滚动时事件菜单不会改变

javascript - 如何扩展谷歌分析以跟踪 AJAX 等(根据 H5BP 文档)

javascript - 使用动态配置选项动态加载 highcharts

javascript - Highcharts:如何更改图表导出中的图例位置?

javascript - 当悬停国家/地区没有可用数据时,Highmaps 中的自定义光标

javascript - 在 iframe 中嵌入 instagram 网页

javascript - Highcharts 柱形图中的最大条形宽度

javascript - Highmaps 标签在不规则路径中居中

Vue.js - Highmaps - 在系列更改时重绘 map