attach events to SVG paths

后端 未结 1 1105
爱一瞬间的悲伤
爱一瞬间的悲伤 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 then clicking inside it (on the fill) will trigger the event handler:

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

        
    
    $('#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/

    
    

    0 讨论(0)
提交回复
热议问题