如何完美循环 feTurbulence 动画
我正在使用以下内容并第一次尝试 SMIL 动画
。
如果你看一下,你会发现动画不流畅,最后有一个跳跃。
我怎样才能让它顺利运行而不发生任何跳跃?
<svg class="layer1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200">
<defs>
<filter id="trip">
<feTurbulence id="turbulence" baseFrequency="10" numOctaves="20" seed="10" stitchTiles="stitch">
<animate id="noiseAnimate" attributeName="baseFrequency" attributeType="XML" from="10" to="15" begin="0s" dur="5s" repeatCount="indefinite"></animate>
</feTurbulence>
<feDisplacementMap in="SourceGraphic" scale="1"></feDisplacementMap>
</filter>
</defs>
<rect class="bg" id="bg" width="200" height="200" fill="black">
</rect>
<rect class="bg" id="bg" x="50" y="50" width="30" height="30" fill="white" filter="url(#trip)">
</rect>
</svg>
I am working with this following and trying SMIL animation
for the first time.
If you take a look, you would realize that the animation is not smooth, there is a jump at the end.
How can I make this to run smoothly without any jump?
<svg class="layer1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200">
<defs>
<filter id="trip">
<feTurbulence id="turbulence" baseFrequency="10" numOctaves="20" seed="10" stitchTiles="stitch">
<animate id="noiseAnimate" attributeName="baseFrequency" attributeType="XML" from="10" to="15" begin="0s" dur="5s" repeatCount="indefinite"></animate>
</feTurbulence>
<feDisplacementMap in="SourceGraphic" scale="1"></feDisplacementMap>
</filter>
</defs>
<rect class="bg" id="bg" width="200" height="200" fill="black">
</rect>
<rect class="bg" id="bg" x="50" y="50" width="30" height="30" fill="white" filter="url(#trip)">
</rect>
</svg>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
让我们忽略您的动画是否是一个好的选择的问题,只看一下所涉及的语法。
此动画的行为与 CSS property< 相同/a>
动画方向:正常
:从 10 移动到 15 后,它会跳回到 10 并重新开始。
虽然 CSS 具有值
animation-direction:alternate
来描述平滑地前后移动的动画,但 SMIL 不存在这种情况。相反,您必须描述具有三个值的运动:起始值、结束值和再次起始值。这不能用from
和to
属性来描述,而是用值
。此外,您还必须设置
keyTimes
属性。在 0...1 的间隔中,它描述了相对于简单持续时间何时达到该值。注意:要设置
baseFrequency
动画,您必须设置stitchTiles="noStitch"
,否则频率会以离散步骤更改,导致 Perlin 单元大小 始终是原始过滤器区域大小的整数部分。Let's ignore the question whether your animation is a good choice, and just look at the syntax involved.
The behavior of this animation is just the same as the CSS property
animation-direction: normal
:After moving from 10 to 15, it jumps back to 10 and starts over.
While CSS has a value of
animation-direction: alternate
to describe an animation that moves smoothly forth and back, the same does not exist for SMIL. Instead, you have to describe a movement that has three values: the start value, the end value, and the start value again. This cannot be described with thefrom
andto
attributes, but withvalues
.Additionally, you have to set the
keyTimes
attribute. In an interval of 0...1 it describes when, relative to the simple duration, the value is reached.Note: For animating
baseFrequency
, you have to setstitchTiles="noStitch"
, as otherwise the frequency is changed in such discrete steps that the Perlin cell size is always an integral fraction of the primitive filter region size.