css - 使用 css 动画 svg 路径填充

标签 css animation svg

可以使用 css 更改 svg 填充。但是我没有设法创建动画。 这是我的 svg 对象:

<svg version="1.1" id="tick" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="100%" height="100%" viewBox="0 0 60 60" enable-background="new 0 0 60 60" xml:space="preserve"> 
<rect id="fill" x="21" y="26" width="60" height="60"/>
</svg>

并且,使用 SASS:

@include keyframes(loading)
  0%
    fill: black
  50%
    fill: white
  100%
    fill: black
#fill
  fill: white
  @include animation(loading 3s infinite)

我做错了什么?

最佳答案

编辑

好的,看起来像这样的东西应该可以工作。

    <svg version="1.1" id="tick" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="100%" height="100%" viewBox="0 0 60 60" enable-background="new 0 0 60 60" xml:space="preserve"> 
  <style type="text/css" >
        <![CDATA[

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

          #fill {
              fill: black;
              animation-name: fill;
              animation-duration: 3s;
              animation-iteration-count: infinite;
          }

        ]]>
    </style>
    <rect id="fill" x="21" y="26" width="60" height="60"/>
</svg>

示例如下:http://jsbin.com/ayiheb/2/edit

关于css - 使用 css 动画 svg 路径填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14756422/

相关文章:

CSS 层次结构 - div 内的 div

html - 如何从 Firefox 中的图像中删除多余的空间?

javascript - 多个嵌入式 SVG 的事件监听器

javascript - 使用 CSS 设置 SVG 样式

css - 媒体查询断点 1218px

数据库中特定 Id 的 Css 样式表?

jquery - 向后和向前滚动 jQuery 动画

android - ActivityOptions.makeSceneTransitionAnimation 在具有多个 View 的 kotlin 中不起作用

javascript - 在现代 jQuery 动画中 setInterval() 和 setTimeout() 是坏事吗?

javascript - 如何访问 svg 内部 id 并让 CSS 更改该 id 的填充颜色?