Mouseover on SVG circles

前端 未结 3 1007
不思量自难忘°
不思量自难忘° 2021-01-02 01:20

I\'m very new to SVG, so please forgive me if this is a basic question.

I would like to draw circles on the screen and respond whenever the user mouses over each cir

3条回答
  •  耶瑟儿~
    2021-01-02 02:09

    No library is needed for this. Given the following SVG:

    
    
      
      
    
    
    

    You could use CSS or Javascript to have these circles change in some way related to the mouse.

    For a simple hover in css you can do something like:

    #circle1:hover {
      fill: blue;
    }
    

    Or any JavaScript mouse event like so:

    document.getElementById('circle2').addEventListener('click', function(e) {
        e.currentTarget.setAttribute('fill', '#ff00cc');
    });
    

    Here is a demo for you to check out: http://codepen.io/ZevanRosser/pen/bdYyLp

提交回复
热议问题