SVG 笔划未显示在 clipPath 内部

SVG stroke not showing inside of clipPath

我有以下 Codepen,我在其中尝试为图像周围的圆圈设置动画。

到目前为止,我有一个正在裁剪图像的圆形 SVG,但它没有在 clipPath 中显示笔画。

如何显示边框?

class App extends React.Component {
  render() {
    return (
      <svg width='48' height='48'>
        <defs>
          <clipPath id='circleView'>
            <circle cx='24' cy='24' r='23' fill='none' stroke='red' strokeWidth='2' />
          </clipPath>
        </defs>
        <image width='48' height='48' xlinkHref={'https://source.unsplash.com/random'} clipPath='url(#circleView)' />
      </svg>
    )
  }
}

正如罗伯特所说,clip-path 行中的子 SVG 图形未显示。

因此,对于动画,您需要在 clip-path

之外添加另一个圆圈

<circle cx="25" cy="24" r="14" fill="none" stroke="red" strokeWidth="2" />

.container {
    width:25%;
 height:25%;
   }
<div class="container">
   <svg  viewBox="0 0 48 48" >
        <defs>
          <clipPath id='circleView'>
            <circle cx='24' cy='22' r='16' fill='none' stroke='red' stroke-width='2' />
          </clipPath>
        </defs>
        <image width="100%" height="100%"   xlink:href='https://i.stack.imgur.com/O9eO8.jpg' 
       clip-path='url(#circleView)' />
  <circle cx='24' cy='22' r='16' fill='none' stroke='red' strokeWidth='2' /> 
</svg>
  </div>

要为圆圈设置动画,请使用 stroke-dashoffset 属性中从最大值到零的更改。 values="(100.48;0)"

点击后开始动画

.container {
    width:25%;
 height:25%;
   }
<div class="container">
   <svg id="svg1" viewBox="0 0 48 48">
        <defs>
          <clipPath id='circleView'>
     <circle cx='24' cy='22' r='16' fill='none' stroke='red' stroke-width='2' />
          </clipPath>
        </defs>
        <image width="100%" height="100%" xlink:href='https://i.stack.imgur.com/O9eO8.jpg' clip-path='url(#circleView)' />
 <circle  transform="rotate(-90 24 22)" cx="24" cy="22" r="16" fill='none' stroke='red' strokeWidth='2' 
      stroke-dasharray="100.48"   stroke-dashoffset="100.48" >
            <animate
              attributeName="stroke-dashoffset"
              dur="1s"
              begin="svg1.click"
              values="100.48;0"
              fill="freeze"/>
 </circle>  
      </svg>

  </div>

带有 CSS

的动画变体

我在圆形​​动画中添加了透明动画。

鼠标悬停时动画开始。

.container {
    width:25%;
 height:25%;
   }  
   #crc1 {
   fill:skyblue;
   stroke-width:1;
   stroke:red;
   stroke-dasharray:100.48;
   stroke-dashoffset:100.48;
    fill-opacity:0.9;
     }
   
   #crc1:hover {
    animation: dash 1.5s ease-out forwards;
      }
   
    @keyframes dash {
  0% { stroke-dashoffset: 100.48; fill-opacity:0.9; }
  50% { fill-opacity:0.45;}
  100% { stroke-dashoffset: 0; fill-opacity:0; }
   }
   
   #img1 {
   clip-path: url(#circleView);
     }
<div class="container">
   <svg id="svg1" viewBox="0 0 48 48">
        <defs>
          <clipPath id='circleView'>
            <circle cx='24' cy='22' r='16'/>
          </clipPath>
        </defs>
        <image width="100%" height="100%" xlink:href='https://i.stack.imgur.com/O9eO8.jpg' 
       clip-path='url(#circleView)' />
         <circle id="crc1"   cx="24" cy="22" r="16" />
          
      </svg>

  </div>