FakeSmile with IE9

大憨熊 提交于 2019-12-01 23:53:03

问题


I'm trying to fake SMIL support in IE9 with FakeSmile

I'm creating the SVG element dynamically, adding a rect element with animate element and calling beginElement(). IE9 gives me an error: Object doesn't support property or method 'beginElement'

Static SVG works: http://jsfiddle.net/FG3PG/1/

How do I use FakeSmile to fix it? The following shows what I'm trying to do: http://jsfiddle.net/DgMDV/13/

And here is the same code:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE HTML><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <script type="text/javascript" src="http://bazaar.launchpad.net/~smilteam/smil/MAIN/download/head:/smil.user.js-20080305202719-59ane0zgfr5f3vz8-1/smil.user.js"></script>
</head>
<body>
<meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" />
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" baseProfile="full" height="200">
   <rect class="drag resize" x="10" y="10" width="100" height="50" fill="#c66" />
</svg>
<script type="text/javascript">
    var svg   = document.getElementsByTagName('svg')[0];
    var svgNS = svg.getAttribute('xmlns');
    var rect = document.getElementsByTagName('rect')[0];

    var animation = document.createElementNS(
        "http://www.w3.org/2000/svg", "animate");
    animation.setAttributeNS(null, 'attributeName', 'x');
    animation.setAttributeNS(null, 'dur', 0.5);
    animation.setAttributeNS(null, 'begin', 'indefinite');
    animation.setAttributeNS(null, 'fill', 'freeze');
    animation.setAttributeNS(null, 'to', 100);
    rect.appendChild(animation);
    animation.beginElement();
</script>
</body>
</html>

回答1:


Fenring (leunen-d) anwered that fakesmil doesn't support dynamic animations and that it could be added with the following function: https://answers.launchpad.net/smil/+question/203333

function registerAnimation(anim) {
    var targets = getTargets(anim);
    var elAnimators = new Array();
    for(var i=0; i<targets.length ;i++) {
      var target = targets[i];
      var animator = new Animator(anim, target, i);
      animators.push(animator);
      elAnimators[i] = animator;
    }
    anim.animators = elAnimators;
    var id = anim.getAttribute("id");
    if (id)
      id2anim[id] = anim;
    for(var i=0; i<elAnimators.length ;i++)
      elAnimators[i].register();
}



回答2:


It seems you're setting a property incorrectly:

animation.setAttributeNS(null, 'begin', 'indefinite');

Change the property name to match the value:

animation.setAttributeNS(null, 'repeatCount', 'indefinite');


来源:https://stackoverflow.com/questions/11459460/fakesmile-with-ie9

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!