attach events to SVG paths

后端 未结 1 1104
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-13 09:58

I have a SVG map in my html with the tag. and I want to attach events so I can click them and trigger some events. I know I can attach click event u

相关标签:
1条回答
  • 2020-12-13 10:39

    If you fill a <path> then clicking inside it (on the fill) will trigger the event handler:

    Demo: http://jsfiddle.net/TmsrP/1/

    <path id="sauce" fill="#f00" … />    
    
    $('#sauce').on('click',function(){ … });
    

    You can choose to explicitly fill the path with the color transparent and mouse events will still be caught:

    Demo: http://jsfiddle.net/TmsrP/2/

    <path fill="transparent" … />
    
    0 讨论(0)
提交回复
热议问题