admin管理员组文章数量:1324849
Is there a way to add a region over a line path in an svg-generated graph?
I want a user to be able to hover near , not just over, a line on a line chart and have things happen after the mouseover.
Currently, with the code I have, you have to mouseover the actual line. But I want to set a region around the line.
(Adding padding to the path doesn't seem to work)
Is there a way to add a region over a line path in an svg-generated graph?
I want a user to be able to hover near , not just over, a line on a line chart and have things happen after the mouseover.
Currently, with the code I have, you have to mouseover the actual line. But I want to set a region around the line.
(Adding padding to the path doesn't seem to work)
Share Improve this question asked Apr 16, 2015 at 15:12 autoauto 1,1733 gold badges19 silver badges50 bronze badges 4- 1 just create an invisible rectangle (region) so when you hover over that rect your mouseover event fires – AJ_91 Commented Apr 16, 2015 at 15:20
- Am I appending the rect to the path or the path to the rect? – auto Commented Apr 16, 2015 at 15:40
- just append the rect to whatever you're appending the path to but append the path to it first so the rect gets created on top of the path – AJ_91 Commented Apr 16, 2015 at 15:43
- That makes sense. Thanks. This seems to work. Now I just have to figure out how to size the rect appropriately. – auto Commented Apr 16, 2015 at 18:24
1 Answer
Reset to default 9My approach would be to draw a second path
over the first, which uses the same data and line function, but is transparent and with a larger stroke-width
.
Then attach the mouseover
and mouseout
listeners to the fatter line.
Fiddle here: http://jsfiddle/henbox/u0vz96qe/1/
Note that for demo purposes, the fatter line is not fully transparent. To make it invisible, just change
.fatpath {
...
opacity:0.1;
}
to be opacity:0;
本文标签: javascriptAdd region around SVG path for mouseoverStack Overflow
版权声明:本文标题:javascript - Add region around SVG path for mouseover - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742121418a2421721.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论