CSS 背景图像 *.svg 动画不起作用

标签 css html animation svg background

我有动画 svg 文件,我想将它用作 div 的背景图像

div { background-image: url('anim.svg'); }

图像显示但动画不工作。

附言我不能在 html 中使用 svg-object,因为我有很多类似的对象,而且 svg-object 的代码并不短。

更新:svg 文件代码:

    <?xml version="1.0" encoding="utf-8"?>
<svg height="69" width="62" class="hexagon" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
    <polygon points="30 0, 60 16, 60 50, 30 68, 0 50, 0 16" style="fill: none; stroke:#fff;stroke-width:1" />
    <polygon points="33 3, 33 3" style="fill: none; stroke:#fff;stroke-width:1">
        <animate attributeName="points" dur="500ms" to="33 3, 59 48" fill="freeze" />
    </polygon>
    <polygon points="28 2, 28 2" style="fill: none; stroke:#fff;stroke-width:1">
        <animate attributeName="points" dur="500ms" to="28 2, 0 49" fill="freeze" />
    </polygon>
    <polygon points="3 51, 3 51" style="fill: none; stroke:#fff;stroke-width:1">
        <animate attributeName="points" dur="500ms" to="3 51, 57 51" fill="freeze" />
    </polygon>
</svg> 

最佳答案

您可以使用 svg:use 来重复相似的对象,例如:

<svg>
  <defs>
    <g id="shape">
        <rect x="50" y="50" width="50" height="50" />
        <circle cx="50" cy="50" r="50" />
    </g>
  </defs>
</svg>

此代码将呈现相同的对象:

<svg>
  <use xlink:href="#shape" x="200" y="50" />
</svg>

关于CSS 背景图像 *.svg 动画不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28633655/

相关文章:

css - 是否有 CSS 父级选择器?

html - 页面底部的小线

swift - contentoffset UIScrollView Swift 的平滑移动

ios - 使用 SnapKit 约束动画

html - 其他类存在时的 CSS 不透明度

javascript - 像工具提示一样显示 Div - Div 需要定位在单击元素旁边

javascript - 如何制作填充视口(viewport) 50% 的内容 block ?

android - 似乎 windowAnimationStyle 被忽略了,如何为自定义对话框设置动画?

php - 如何对齐页面右侧的链接/图片列表,并阻止它们重叠?

php - 我想插入到一个表中,从 php 中同一数据库中的另一个表获取的数据