firefox - 动画 SVG 在 Firefox 中不起作用,在 Chrome 中有效

标签 firefox svg svg-animate

我不确定我需要在这个 SVG 中修改什么才能使其与 Firefox 兼容?动画在其他浏览器中工作正常,但在 Firefox 中它只是一个静态图像并且没有动画。

<svg width='360px' height='360px' xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid" class="uil-balls">
    <rect x="0" y="0" width="100" height="100" fill="none" class="bk"></rect>
    <g transform="rotate(0 50 50)">
        <circle r="3" cx="30" cy="50">
            <animateTransform attributeName="transform" type="translate" begin="0s" repeatCount="indefinite" dur=".75s" values="0 0;13.819660112501051 -19.02113032590307" keyTimes="0;1" />
            <animate attributeName="fill" dur=".75s" begin="0s" repeatCount="indefinite" keyTimes="0;1" values="#DB3341;#42a3cf" />
        </circle>
    </g>
    <g transform="rotate(72 50 50)">
        <circle r="3" cx="30" cy="50">
            <animateTransform attributeName="transform" type="translate" begin="0s" repeatCount="indefinite" dur=".75s" values="0 0;13.819660112501051 -19.02113032590307" keyTimes="0;1" />
            <animate attributeName="fill" dur=".75s" begin="0s" repeatCount="indefinite" keyTimes="0;1" values="#42a3cf;#76478a" />
        </circle>
    </g>
    <g transform="rotate(144 50 50)">
        <circle r="3" cx="30" cy="50">
            <animateTransform attributeName="transform" type="translate" begin="0s" repeatCount="indefinite" dur=".75s" values="0 0;13.819660112501051 -19.02113032590307" keyTimes="0;1" />
            <animate attributeName="fill" dur=".75s" begin="0s" repeatCount="indefinite" keyTimes="0;1" values="#76478a;#99c763" />
        </circle>
    </g>
    <g transform="rotate(216 50 50)">
        <circle r="3" cx="30" cy="50">
            <animateTransform attributeName="transform" type="translate" begin="0s" repeatCount="indefinite" dur=".75s" values="0 0;13.819660112501051 -19.02113032590307" keyTimes="0;1" />
            <animate attributeName="fill" dur=".75s" begin="0s" repeatCount="indefinite" keyTimes="0;1" values="#99c763;#ebbc3c" />
        </circle>
    </g>
    <g transform="rotate(288 50 50)">
        <circle r="3" cx="30" cy="50">
            <animateTransform attributeName="transform" type="translate" begin="0s" repeatCount="indefinite" dur=".75s" values="0 0;13.819660112501051 -19.02113032590307" keyTimes="0;1" />
            <animate attributeName="fill" dur=".75s" begin="0s" repeatCount="indefinite" keyTimes="0;1" values="#ebbc3c;#DB3341" />
        </circle>
    </g>
    <circle r="6" cx="50" cy="50" stroke="black" fill="none" stroke-width="2.75"></circle>
</svg>

最佳答案

SMIL 规范说持续时间不能以小数点开头。 Firefox 实现了所写的规范,而 Chrome 没有。从 dur=".75s"转换为 dur="0.75s"将以跨浏览器的方式修复它。

<svg width='360px' height='360px' xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid" class="uil-balls">
    <rect x="0" y="0" width="100" height="100" fill="none" class="bk"></rect>
    <g transform="rotate(0 50 50)">
        <circle r="3" cx="30" cy="50">
            <animateTransform attributeName="transform" type="translate" begin="0s" repeatCount="indefinite" dur="0.75s" values="0 0;13.819660112501051 -19.02113032590307" keyTimes="0;1" />
            <animate attributeName="fill" dur="0.75s" begin="0s" repeatCount="indefinite" keyTimes="0;1" values="#DB3341;#42a3cf" />
        </circle>
    </g>
    <g transform="rotate(72 50 50)">
        <circle r="3" cx="30" cy="50">
            <animateTransform attributeName="transform" type="translate" begin="0s" repeatCount="indefinite" dur="0.75s" values="0 0;13.819660112501051 -19.02113032590307" keyTimes="0;1" />
            <animate attributeName="fill" dur="0.75s" begin="0s" repeatCount="indefinite" keyTimes="0;1" values="#42a3cf;#76478a" />
        </circle>
    </g>
    <g transform="rotate(144 50 50)">
        <circle r="3" cx="30" cy="50">
            <animateTransform attributeName="transform" type="translate" begin="0s" repeatCount="indefinite" dur="0.75s" values="0 0;13.819660112501051 -19.02113032590307" keyTimes="0;1" />
            <animate attributeName="fill" dur="0.75s" begin="0s" repeatCount="indefinite" keyTimes="0;1" values="#76478a;#99c763" />
        </circle>
    </g>
    <g transform="rotate(216 50 50)">
        <circle r="3" cx="30" cy="50">
            <animateTransform attributeName="transform" type="translate" begin="0s" repeatCount="indefinite" dur="0.75s" values="0 0;13.819660112501051 -19.02113032590307" keyTimes="0;1" />
            <animate attributeName="fill" dur="0.75s" begin="0s" repeatCount="indefinite" keyTimes="0;1" values="#99c763;#ebbc3c" />
        </circle>
    </g>
    <g transform="rotate(288 50 50)">
        <circle r="3" cx="30" cy="50">
            <animateTransform attributeName="transform" type="translate" begin="0s" repeatCount="indefinite" dur="0.75s" values="0 0;13.819660112501051 -19.02113032590307" keyTimes="0;1" />
            <animate attributeName="fill" dur="0.75s" begin="0s" repeatCount="indefinite" keyTimes="0;1" values="#ebbc3c;#DB3341" />
        </circle>
    </g>
    <circle r="6" cx="50" cy="50" stroke="black" fill="none" stroke-width="2.75"></circle>
</svg>

关于firefox - 动画 SVG 在 Firefox 中不起作用,在 Chrome 中有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44850876/

相关文章:

javascript - 网络爬虫 : Using Perl's MozRepl module to deal with Javascript

firefox - 如何让 TiddlySnip 在 Firefox 中工作?

javascript - 使用 D3 JS 在桑基图中显示百分比

android - 图像触摸选择区

javascript - Internet Explorer 10 不显示 svg 路径(d3.js 图)

css - svg 文件中星星的旋转动画

javascript - "NetworkError when attempting to fetch resource."仅在 Firefox 上

ios - 如何在不使用 UIWebView 的情况下在 iOS 中显示动画 svg 文件

javascript - 如何在 Javascript 中设置 SVG CSS 属性的样式?

css - FF29+ 中的 input[type=number] 占位符颜色