我这里问了一个关于这个图的问题,但是怎么把这个动画全部加到css中,比如给个class,那么就会有动画。我想做到这一点,例如,当单击一个按钮时,数字会被平滑地覆盖。
svg text {
font-family: sans-serif;
text-anchor: middle;
font-weight: bold;
font-size: 70px;
fill: url(#fendTestGrad);
}
#fendTestGrad .start {
stop-color: #c2c5cc;
}
#fendTestGrad .end {
stop-color: #8f98a1;
}
svg {
background: linear-gradient(135deg, rgba(73,85,97,1) 0%, rgba(74,88,101,1) 100%);
}
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewbox="0 0 100 100">
<defs>
<linearGradient id="fendTestGrad" x1="52%" y1="52%" x2="48%" y2="48%">
<animate
attributeName="x1"
from="0" to=".52"
dur="3s"
repeatCount="1">
</animate>
<animate
attributeName="y1"
from="0" to=".52"
dur="3s"
repeatCount="1">
</animate>
<animate
attributeName="x2"
from="0" to=".48"
dur="3s"
repeatCount="1">
</animate>
<animate
attributeName="y2"
from="0" to=".48"
dur="3s"
repeatCount="1">
</animate>
<stop class="start"></stop>
<stop class="start"></stop>
<stop class="end"></stop>
</linearGradient>
</defs>
<text x="50%" y="70">60</text>
</svg>
试试这样
您需要使用属性
begin。例如,此代码在单击此对象时启动动画:问题是
<linearGradient>它不是可以点击的对象。当您单击文本时,不是单击元素<text>,也不是<linearGradient>. 因此,您需要设置<text>一些id:然后安排
<animate>如下:工作代码: