我有<g>
元素,其中包含<rect>
和<image>
。<g>
有鼠标事件侦听器。问题是,当我将鼠标从rect移到图像(在同一个g
中)时,将触发mouseout事件(后面跟着'mouseover')。
举个例子。(和小提琴手)
var x = 120;
var g = d3.select("svg")
.append("g")
.on('mouseover', function() {
d3.select(this).append("text").text("mouseover").attr('transform','translate(0,'+x+')');
x+=20;
})
.on('mouseout', function() {
d3.select(this).append("text").text("mouseout").attr('transform','translate(0,'+x+')');
x+=20;
})
g.append("rect")
.attr('width', 100)
.attr('height', 100)
.style('fill', 'lightgreen')
g.append('image')
.attr("width", 30)
.attr("height", 30)
.attr("x", 35)
.attr("y", 35)
.attr("xlink:href","https://www.gravatar.com/avatar/f70adb32032d39add2559c2609a90d03?s=128&d=identicon&r=PG")
如何防止鼠标退出事件的触发?
发布于 2013-07-25 03:37:10
当在父容器上使用mouseout和mouseover时,当鼠标在子代元素之间移动时会得到事件。如果您只想知道鼠标进入或离开父节点的位置,请使用莫塞莱。
发布于 2016-01-19 04:06:46
使用
onpointerleave
问题解决了。
https://stackoverflow.com/questions/17854897
复制相似问题