我有一个SVG用一个按钮覆盖一个div。我知道我可以通过为我的SVG设置“指针-事件:无;”通过SVG传递鼠标事件。然而,当我这样做时,SVG将不再识别鼠标事件。
<body>
<div id="website">
<form action="input_button.htm">
<p>
<textarea cols="20" rows="4" name="text"></textarea>
<input type="button" name="Text 1" value="show text"
onclick="this.form.text.value='Test'">
</p>
</form>
</div>
<div id="svgRect">
<svg width="1845" height="140">
<rect id="r0"></rect>
</svg>
</div>
</body>我希望我的SVG能够识别鼠标在它上面的时间,但是将点击传递给元素(divs/按钮/.)在它的下面。所以我的SVG只应该是悬停事件的目标,我的按钮应该是点击事件的目标。
在其他一些方法中,我尝试过这样的方法:-什么都没有用。
.on("mousedown", function(d,i){
d3.select("#r0")
.style("pointer-events", "none");
d3.select("#website")
.style("pointer-events", "auto");}
.on("mouseup", function(d,i){
d3.select("#r0")
.style("pointer-events", "auto");
d3.select("#website")
.style("pointer-events", "none");
}这个想法是在我按下鼠标按钮时禁用指针事件,并在我释放它时再次启用它们。
有人知道这个问题的解决办法或工作吗?谢谢!
发布于 2016-07-20 17:13:25
这里有一个更简单的解决方案:将pointer-events: none;保存在svg中,但是将pointer-events: fill添加到poligon、path或任何按钮中,这样,空空间是透明的,但是单击按钮是明智的。
https://stackoverflow.com/questions/28282811
复制相似问题