【问题标题】:SVG animation doesn't run on IE9/IE10SVG 动画不能在 IE9/IE10 上运行
【发布时间】:2019-02-28 00:05:13
【问题描述】:

您好,我有一段 HTML 代码,它基本上是一个 SVG 动画。这适用于 Chrome 和 Firefox,但不适用于 IE9/IE10。

有什么办法吗?

需要至少在 Chrome/Firefox/IE 9 及更高版本中工作的单一代码库。

<!DOCTYPE html>  
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>

<body>

    <div id='svgnotsupported' style='visibility: hidden;'>
        <h1>This application requires SVG support</h1>
    </div>

    <div id='svgsupported' style='visibility: hidden'></div>

    <script>

        var svgsupport;

        window.onload = function supportsSvg() {

            var ua = navigator.userAgent;
            var M = ua.match(/(chrome)\/?\s*(\.?\d+(\.\d+)*)/i);
            var b =   document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure",  "1.0")
            if(b || M) {
                svgsupport = document.getElementById('svgsupported');
            } else {
                svgsupport = document.getElementById('svgnotsupported');
            }

            svgsupport.style.visibility = 'visible';

        }

    </script>

    <svg id="no_fewer_than_N_events_E_between_event_Q_and_first_R_thereafter" width="588" height="578" version="1.1" xmlns="http://www.w3.org/2000/svg">
        <defs>
            <marker id="Triangle" viewBox="0 0 20 20" refX="20" refY="10" markerUnits="strokeWidth" markerWidth="8" markerHeight="6" orient="auto">
                <path d="M 0 0 L 20 10 L 0 20 z" fill="blue"/>
            </marker>
            <marker id="Circle" viewBox="0 0 10 10" refX="5" refY="5" markerUnits="strokeWidth" markerWidth="6" markerHeight="6" orient="auto">
                <circle cx="5" cy="5"  r="3" fill="blue"/>
            </marker>
        </defs>
        <g>
            <path id="_4JpShw3P09cVj6Vb1lR041" d="M 399.0,228.0 a 20.0 40.0, 0, 1, 0, 54.0 0.0" style="fill:none;stroke:blue ;stroke-width:3" marker-end="url(#Triangle)" />
            <rect id="anim_4JpShw3P09cVj6Vb1lR041" x="-5" y="-5" width="10" height="10" fill="red">
            <animateMotion  path="M 399.0,228.0 a 20.0 40.0, 0, 1, 0, 54.0 0.0" dur="5s" rotate="auto" repeatCount="indefinite" begin="1s"  />
            </rect> 
        </g>
        <g>
            <rect id="_0uuE73jF5kmqe14s6Y02NF" x="372" y="165" rx="10.0" ry="6.0" width="109" height="63" style="fill:white;stroke:black;stroke-width:4;opacity:0.5">
                <animate id="anim_0uuE73jF5kmqe14s6Y02NF" attributeName="stroke" attributeType="CSS" from="lime" to="black" dur="2s" repeatCount="indefinite" />
            </rect>
        </g>
    </svg>

</body>

</html>

【问题讨论】:

标签: internet-explorer animation svg


【解决方案1】:

您可以使用FakeSmile 库为 IE 添加动画支持。

【讨论】:

  • 如何使用fakeSMIL?我可以通过任何想法或链接吗?
  • 罗伯特感谢您的回复。我已经下载了 smil.use.js 文件并在我的 html 文件中添加了参考,但它仍然无法正常工作 IE。我的问题是我必须在我的 html 文件中更改基于 SMIL 的 svg 标签还是我必须在本地 Web 服务器上运行这个 html 文件?
  • 当我在 IE9 中查看来自@RobertLongson 的示例时,它不会为我制作动画。
  • 为了在 IE9 中工作,您必须在头部包含这样的脚本:jsfiddle.net/FG3PG/206
  • 很好的解决方案!但是,当我在&lt;img&gt; 标签中使用svgsrc 时,它不起作用
猜你喜欢
  • 2013-02-23
  • 2017-10-10
  • 2019-06-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-04
  • 1970-01-01
  • 2015-05-30
相关资源
最近更新 更多