admin 管理员组文章数量: 1086019
I have <g>
element with <rect>
and <image>
inside. <g>
has mouseout event listener. The problem is that when I move mouse from rect to image (within the same g
), the mouseout event is triggered (followed by 'mouseover').
Here's example. (and Jsfiddle)
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",";d=identicon&r=PG")
How to prevent the mouseout event from triggering?
I have <g>
element with <rect>
and <image>
inside. <g>
has mouseout event listener. The problem is that when I move mouse from rect to image (within the same g
), the mouseout event is triggered (followed by 'mouseover').
Here's example. (and Jsfiddle)
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./avatar/f70adb32032d39add2559c2609a90d03?s=128&d=identicon&r=PG")
How to prevent the mouseout event from triggering?
Share Improve this question asked Jul 25, 2013 at 10:03 eagoreagor 10.1k9 gold badges52 silver badges51 bronze badges 2- tried hover? gives the same effect? – user2587132 Commented Jul 25, 2013 at 10:12
- This question might help. – Lars Kotthoff Commented Jul 25, 2013 at 11:14
2 Answers
Reset to default 12When you use mouseout and mouseover on a parent container, you get events when the mouse moves between descendant elements. If you only want to hear where the mouse enters or leaves the parent, use mouseenter and mouseleave instead.
Using
onpointerleave
solved problem.
本文标签:
版权声明:本文标题:javascript - SVG: Moving mouse to <image> element triggers mouseout event of parent <g> element (d3. 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744096427a2532983.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论