4

jqueryでDOM要素を動的に追加しながら、SVG要素のアニメーションを実行しようとしています。これらの要素<body>を以下のように内部に追加すると、動作します。これの動作サンプルは http://jsfiddle.net/bZdfH/2/です

<svg>
    <script type="text/ecmascript" xlink:href="http://leunen.me/fakesmile/smil.user.js"/>
    <circle cx="60" cy="60" r="20" style="fill: pink; stroke: red;" >
    <animate attributeName="r" dur="4s" values="20; 0; 20" repeatCount="indefinite"/>
    </circle>
 </svg>

動的に追加すると、IE ではアニメーションが開始されませんが、Chrome と FireFox では動作します。

<svg>
 <script type="text/ecmascript" xlink:href="http://leunen.me/fakesmile/smil.user.js"/>
 <circle cx="60" cy="60" r="20" style="fill: pink; stroke: red;" onmouseover="changeImage(this)" >
 </circle>
</svg>
<script>
    function changeImage(circle) {
      while (circle.firstChild) {
        circle.removeChild(circle.firstChild);
      }
      circle.setAttributeNS(null, "fill", "blue");
        var animate = document.createElementNS("http://www.w3.org/2000/svg", "animate");
        animate.setAttributeNS(null, "attributeName", "r");
        animate.setAttributeNS(null, "values", "20;0;20");
        animate.setAttributeNS(null, "dur", "6s");
        animate.setAttributeNS(null, "repeatCount", "indefinite");
        circle.appendChild(animate);
      }
</script>

これがワーキングサンプルのjsfiddleです。誰か助けてください??

4

1 に答える 1

1

IE は SMIL アニメーションをサポートしていません。ソース: http://caniuse.com/#search=svg

于 2013-12-13T13:50:03.647 に答える