2016-11-18 128 views
0

我已经创建了一个svg文件,轮廓在页面加载时被“绘制”。 动画完成后,我想填写轮廓。SVG动画。绘制后填充路径

所以这就是我所做的。

有多条路径。这里是一个:

<path id="b1" class="b1" d="M95.4,204.9a31.7,31.7,0,0,1,23,9.6,32.8,32.8,0,0,1,6.9,10.8,38.7,38.7,0,0,1,0,27.4,32.8,32.8,0,0,1-6.9,10.8,31.7,31.7,0,0,1-23,9.6,25.7,25.7,0,0,1-11.9-2.6,25.4,25.4,0,0,1-8.3-6.8v7.7H61V174H75.1v40.3a25.4,25.4,0,0,1,8.3-6.8A25.7,25.7,0,0,1,95.4,204.9Zm-1.7,13.3a19.5,19.5,0,0,0-8,1.6,18.5,18.5,0,0,0-6.1,4.4,19.7,19.7,0,0,0-4,6.6,24.6,24.6,0,0,0,0,16.5,19.7,19.7,0,0,0,4,6.6,18.5,18.5,0,0,0,6.1,4.4,20.9,20.9,0,0,0,16.1-.1,18.1,18.1,0,0,0,6.1-4.5,19.7,19.7,0,0,0,3.9-6.6,24.6,24.6,0,0,0,0-16.1,19.8,19.8,0,0,0-3.9-6.6,18.1,18.1,0,0,0-6.1-4.5A19.6,19.6,0,0,0,93.7,218.2Z" transform="translate(-60.5 -173.5)" fill="none" stroke="#1d1d1b" stroke-miterlimit="10"/> 

这是轮廓的动画CSS:

@keyframes offset{ 
    to { 
     stroke-dashoffset: 0; 
    } 
} 

.b1{ 
    animation: offset 2s linear forwards; 
    stroke-dasharray: 324.774; 
    stroke-dashoffset: 324.774; 
} 

直到这里的一切都工作得很好。
两秒钟后动画完成,现在我想填充它。
这是我因子评分我可能做到这一点:

@keyframes fill { 
    0% { 
     fill: white; 
     } 
    100% { 
     fill: black; 
     } 
     } 

     #fill { 
      animation-name: fill; 
      animation-duration: 2s; 
      animation-delay:2s; 
     } 

的问题是,我媒体链接有一个id并分配给path
我试图改变pathid#fill一个class

如果我这样做,大纲动画被覆盖,它只是等待两秒钟。在两秒钟后,路径被动画填充。

我该如何做这项工作? 我想要的是首先动画轮廓,当它们完成时,形状必须被填充。

Thnx。

回答

1

在动画中,您可以拥有任意数量的关键帧。只需在0%到50%之间设置动画路径,然后在50%到100%之间设置动画效果。

在这里你去:

.b1 { 
 
    animation: stroke_fill 4s linear forwards; 
 
    stroke-dasharray: 324.774; 
 
    stroke-dashoffset: 324.774; 
 
} 
 
@keyframes stroke_fill { 
 
    0% { 
 
    fill: white; 
 
    } 
 
    50% { 
 
    fill: white; 
 
    stroke-dashoffset: 0; 
 
    } 
 
    100% { 
 
    fill: black; 
 
    stroke-dashoffset: 0; 
 
    } 
 
}
<svg width="300" height="300" viewBox="0 0 300 300"> 
 
    <path id="b1" class="b1" d="M95.4,204.9a31.7,31.7,0,0,1,23,9.6,32.8,32.8,0,0,1,6.9,10.8,38.7,38.7,0,0,1,0,27.4,32.8,32.8,0,0,1-6.9,10.8,31.7,31.7,0,0,1-23,9.6,25.7,25.7,0,0,1-11.9-2.6,25.4,25.4,0,0,1-8.3-6.8v7.7H61V174H75.1v40.3a25.4,25.4,0,0,1,8.3-6.8A25.7,25.7,0,0,1,95.4,204.9Zm-1.7,13.3a19.5,19.5,0,0,0-8,1.6,18.5,18.5,0,0,0-6.1,4.4,19.7,19.7,0,0,0-4,6.6,24.6,24.6,0,0,0,0,16.5,19.7,19.7,0,0,0,4,6.6,18.5,18.5,0,0,0,6.1,4.4,20.9,20.9,0,0,0,16.1-.1,18.1,18.1,0,0,0,6.1-4.5,19.7,19.7,0,0,0,3.9-6.6,24.6,24.6,0,0,0,0-16.1,19.8,19.8,0,0,0-3.9-6.6,18.1,18.1,0,0,0-6.1-4.5A19.6,19.6,0,0,0,93.7,218.2Z" 
 
    transform="translate(-60.5 -173.5)" fill="none" stroke="#1d1d1b" stroke-miterlimit="10" /> 
 
</svg>

+0

老兄......你是最好的。谢谢,也解释 – Interactive