Style SVG circle with CSS

后端 未结 11 1596
时光取名叫无心
时光取名叫无心 2020-12-14 01:03

So I have my SVG-circle.


   
         


        
相关标签:
11条回答
  • 2020-12-14 01:41

    I am not sure, but you can not full custom a svg only with css. However, if you will do it won't be cross browser. In the past I used svg for creating a complex map and for me the solution was rapheljs.

    EDIT:

    Using @phonicx calculus for radius i modified the code, having something which is able to customize each circle ( in case if you have more ) :

    <svg xmlns="http://www.w3.org/2000/svg" version="1.1">
       <circle data-precentage='100' cx="168" cy="179" r="59" fill="red" />
       <circle data-precentage='120' cx="74" cy="100" r="59" fill="black" /> 
    </svg>
    
    0 讨论(0)
  • 2020-12-14 01:44

    As Phillip suggested in the comment above you can do this with CSS 3 transform.

      circle:hover {
        -webkit-transform: scale(x, y);
      }
    

    ("-webkit" prefix is for Chrome only)

    See https://developer.mozilla.org/en-US/docs/Web/CSS/transform

    Here's a working example with CSS transitions too: http://jsbin.com/sozewiso/2

    0 讨论(0)
  • 2020-12-14 01:53

    As per the SVG 1.1 specification you can't style the r attribute of an SVG circle using CSS https://www.w3.org/TR/SVG/styling.html#SVGStylingProperties. But you can do:

    <circle cx="168" cy="179" r="59"
            fill="white" stroke="black"
            onmouseover="evt.target.setAttribute('r', '72');"
            onmouseout="evt.target.setAttribute('r', '59');"/>
    

    In SVG 2, which is partially supported by some modern browsers, you can style the r attribute of circles using CSS. https://www.w3.org/TR/SVG2/styling.html#PresentationAttributes

    0 讨论(0)
  • 2020-12-14 01:55

    This should work for you.

    jsfiddle

    You need to manipulate the radius and this can only be done via javascript:

    $(function () {
        $("svg circle").on("mouseenter", function () {
    
            var oldR = $(this).attr("r");
    
            var newR = (((oldR*2)/100)*120)/2; // 120% width
    
            $(this).attr("r", newR);
    
        });
    });
    
    0 讨论(0)
  • 2020-12-14 01:55

    I was working on something else and came across this question. I'm doing something similar and using greensock. I animated the scale on a couple circles using Greensock, GSAP. I needed to animate tranformOrigin and the scale property:

    TweenMax.staggerFrom(".circle",1,{scale:0,transformOrigin:"50% 50%",ease:Bounce.easeOut}, .08);
    

    Example https://codepen.io/grmdgs/pen/RgjdPv

    Greensock https://greensock.com/

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