[英]Inhibit mouse interactions for certain svg child elements
这是一个带有圆圈的svg:
svg = d3.select("body").append("svg")
.on("mouseover", function() { console.log("callback");} );
svg.append("circle")
.attr("cx", 50)
.attr("cy",50)
.attr("r",20)
.attr("fill","red");
当我将鼠标悬停在circle
时,为什么mouseover
触发? 我认为是因为其父svg
的子元素?
但我想禁止此操作。 我怎样才能做到这一点?
mouseover函数上的参数似乎未在事件中传递,因此我想出了这种解决方案。
svg = d3.select("body").append("svg")
.on("mouseover", function() {
var event = window.event;
if (event.target.nodeName === "svg") {
console.log("callback");
}
});
svg.append("circle")
.attr("cx", 50)
.attr("cy",50)
.attr("r",20)
.attr("fill","red");
如果要禁止指针交互,请在该元素上设置指针事件 =“ none”。
.attr("pointer-events","none")
容器元素不会在SVG中触发鼠标事件。 仅当将鼠标悬停在该事件包含的任何子图形元素上时,该事件才会被触发。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.