gpt4 book ai didi

html - SVG 动画 : tspan translation

转载 作者:太空宇宙 更新时间:2023-11-04 00:57:16 29 4
gpt4 key购买 nike

我正在尝试在悬停时为 svg 文本元素的每个字母设置动画(制作然后跳转)。为此,我将每个字母都放在 <tspan> 中。并在其上添加动画,无论如何变换不起作用。

<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>

<style type="text/css">
svg text tspan {
fill: #666;
animation:jump 5s linear;
}

@keyframes jump {
100% {
fill: red;
transform: translateY(40px);
}
}
</style>

<body>

<svg overflow="visible">
<text font-size="20px" x="0" y="21"><tspan>t</tspan><tspan>e</tspan><tspan >s</tspan><tspan >t</tspan></text>
<text font-size="20px" x="0" y="42"><tspan>2 </tspan><tspan>l</tspan><tspan>i</tspan><tspan>g</tspan><tspan>n</tspan><tspan>e</tspan></text>
</svg>

</body>
</html>

最佳答案

这通过 SMIL 为每个字母设置动画。这有点重复,因为 SMIL 动画仅适用于单个目标。

我们还必须避免在错误的位置使用空格,否则文本元素会假设我们实际上想要显示它而不是为了整洁。

<svg>
<text y="50 50 50 50">
<tspan>T<animate
attributeName="dy" from="0" to="-40"
dur="5s" begin="mouseover" restart="whenNotActive" /><set
attributeName="fill" to="red"
dur="5s" begin="mouseover" restart="whenNotActive" /></tspan><tspan>e<animate
attributeName="dy" from="0" to="-40"
dur="5s" begin="mouseover" restart="whenNotActive" /><set
attributeName="fill" to="red"
dur="5s" begin="mouseover" restart="whenNotActive" /></tspan><tspan>s<animate
attributeName="dy" from="0" to="-40"
dur="5s" begin="mouseover" restart="whenNotActive" /><set
attributeName="fill" to="red"
dur="5s" begin="mouseover" restart="whenNotActive" /></tspan><tspan>t<animate
attributeName="dy" from="0" to="-40"
dur="5s" begin="mouseover" restart="whenNotActive" /><set
attributeName="fill" to="red"
dur="5s" begin="mouseover" restart="whenNotActive" /></tspan></text>
</svg>

关于html - SVG 动画 : tspan translation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54314670/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com