【问题标题】:SVG text animate font stylesSVG 文本动画字体样式
【发布时间】:2016-04-28 16:28:02
【问题描述】:

我想做一个看起来像谷歌搜索框的动画

我有一个文本路径,其中单词以“粗体”字体显示。

我想让单词动画化,使第一个字母出现“常规”,然后是第一个和第二个,然后是第一个第二个和第三个等等。

这可能与 svg 动画有关吗?

 <svg width="100%" height="100%" viewBox="30 -50 600 500" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1">

  <path id="path1">
    <animate attributeName="d" from="m100,50 h0" to="m100,50 h1100" dur="5s" begin="0s" repeatCount="indefinite" />
  </path>

// this text "types"

  <text font-size="90" font-family="Montserrat" fill='black'>
    <textPath xlink:href="#path1">Google is</textPath>
  </text>

// I want this text to animate the "font-style"

  <text font-size="90" font-family="Montserrat" fill='black' x="100" y="200">
    Google is gold
    <animate attributeType="CSS" ....  />
  </text>

【问题讨论】:

  • 谢谢。我需要给每个 一个 id 来执行此操作吗?我也可以通过在 animate 标签中编写 font-style='regular' 并给每个标签设置不同的 begin="?s" 来制作动画吗?
  • 如果您希望它们链接,请在上一个的 &lt;animation id&gt;.end 事件上为每个设置动画

标签: animation svg


【解决方案1】:

您需要将字母放在 textPath 中的单独标签中,以便您可以使用动画单独定位它们。

我刚刚完成了第一个字母,但如果您愿意,可以将其扩展到所有字母。

 <svg width="100%" height="100%" viewBox="30 -50 600 500" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1">

  <path id="path1">
    <animate attributeName="d" from="m100,50 h0" to="m100,50 h1100" dur="5s" begin="0s" repeatCount="indefinite" />
  </path>

// this text "types"

  <text font-size="90" font-family="Montserrat" fill='black'>
    <textPath xlink:href="#path1">Google is</textPath>
  </text>

// I want this text to animate the "font-style"

  <text font-size="90" font-family="Montserrat" fill='black' x="100" y="200">
    <tspan>G<animate attributeType="CSS" attributeName="font-weight" from="700" to="100" dur="1s" begin="0s" repeatCount="indefinite"/></tspan>oogle is gold
    
  </text>

【讨论】:

  • 这很有帮助。我坚持链接动画。这是我最好的尝试,你能看看吗? plnkr.co/edit/Yg3F37QtUUcdkoHlOIeN?p=info 它应该像这样工作:顶行 - 从 0 开始,每个字母应该一个接一个地出现(可见性隐藏到可见,然后按住)和底行 - 0s 整个单词显示为粗体,每个字母都会发生变化(字体-粗细: 700到100一个接一个,按住)然后我希望整个序列重新开始。
  • 你能再问一个问题并把你的代码放进去吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-09-02
  • 2020-08-22
  • 1970-01-01
  • 1970-01-01
  • 2012-04-19
  • 2017-05-26
  • 1970-01-01
相关资源
最近更新 更多