简体   繁体   English

为什么此网站无法注册点击事件?

[英]Why is this site having trouble registering click events?

I have a map made with d3 that has title that I want to display as hover over tool tip. 我有一个用d3制作的地图,该地图的标题要显示为悬停在工具提示上。 It correctly handles mouse click events for panning and zooming. 它可以正确处理鼠标单击事件以进行平移和缩放。 However, it does not handle mouse overs for tools tips. 但是,它不能处理工具提示的鼠标悬停。

My HTML looks like this: 我的HTML看起来像这样:

<div id="mapwrapper">
    <div id="map">
        <svg width...>

If I set a jquery handler for any mouse event (click/mouseover) it will fire for map wrapper or map, but not for anything in the SVG. 如果我为任何鼠标事件(单击/鼠标悬停)设置了一个jQuery处理程序,它将为地图包装器或地图触发,但不会为SVG中的任何事件触发。

$("#mapwrapper").on("mouseover", function() { //same for click events...
    alert("mapwrapper"); //fires
});
$("#map").on("mouseover", function() {
    alert("map");  //fires
}); 
$("svg").on("mouseover", function() {
    alert("map");   //does not fire
});

I've tried several methods of displaying tooltips and they don't work. 我尝试了几种显示工具提示的方法,但它们不起作用。 I've also tried to setup a simple jquery mouseover alert (just displaying a popup when you run your mouse over an SVG element with a certain class) and that doesn't work. 我还尝试设置一个简单的jquery鼠标悬停警报(当您将鼠标悬停在具有特定类的SVG元素上时仅显示一个弹出窗口),并且不起作用。 So clearly something is messing up the mouseover events on the SVG on the site. 因此很明显,有些事情弄乱了站点上SVG上的鼠标悬停事件。 I know d3 has "events" -- although I don't know much about how they work. 我知道d3有“事件”-尽管我不太了解它们的工作方式。

Interestingly, if I copy and paste the HTML into a new document and then load that document the SVG with register click events 有趣的是,如果我将HTML复制并粘贴到新文档中,然后使用注册点击事件将该文档加载到SVG中

I have set the pointer events property on the SVG to visible and get the same behavior 我已将SVG上的指针事件属性设置为可见并获得相同的行为

How do I debug this problem? 如何调试此问题?

The problem was that I had an SVG rectangle that was blocking the path elements beneath it. 问题是我有一个SVG矩形挡住了它下面的路径元素。 When I hide the SVG rectangle overlaying its children, then the children (which were blocked) register click events. 当我隐藏覆盖其子项的SVG矩形时,子项(被阻止)会注册单击事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM