SVG和CSS3动画无法在IE和Safari中运行

时间:2015-06-28 09:11:25

标签: javascript html5 css3 svg css-animations

我有使用HTML5,CSS3动画和SVG制作动画的代码 line。它只适用于Chrome,Opera和Firefox而且无法正常工作 在IE和Safari中。任何解决方案?

以下是代码:

.line {
  width: 65%;
  margin: 0 auto;
}
#svg path.path {
  stroke-dasharray: 3000;
  stroke-dashoffset: 4000;
  stroke-width: 2;
  -webkit-animation: lines 5s linear forwards;
  -moz-animation: lines 5s linear forwards;
  -ms-animation: lines 5s linear forwards;
  -0-animation: lines 5s linear forwards;
  animation: lines 5s linear forwards;
}
@keyframes lines {
  form {
    stroke-dashoffset: 4000;
  }
  to {
    stroke-dashoffset: 0;
  }
}
@-webkit-keyframes lines {
  form {
    stroke-dashoffset: 4000;
  }
  to {
    stroke-dashoffset: 0;
  }
}
@-moz-keyframes lines {
  form {
    stroke-dashoffset: 4000;
  }
  to {
    stroke-dashoffset: 0;
  }
}
@-ms-keyframes lines {
  form {
    stroke-dashoffset: 4000;
  }
  to {
    stroke-dashoffset: 0;
  }
}
@-o-keyframes lines {
  form {
    stroke-dashoffset: 4000;
  }
  to {
    stroke-dashoffset: 0;
  }
}
<div class="line">
  <svg id="svg" stroke="#000" stroke-miterlimit="1000" id="Layer_1" style="opacity:1;" x="0px" y="0px" viewBox="0 0 960 560" enable-background="new 0 0 960 560" xml:space="preserve">
    <path class="path" fill="#fff" stroke="#000" stroke-miterlimit="1000" stroke-dasharray="11.9901,11.9901" d="M52.652,248.08
      c30.97,37.245,74.957,63.396,122.172,75.244c53.056,13.313,109.816,9.162,161.756-7.968
      c42.308-13.953,83.007-37.533,108.174-74.156c4.655-6.774,8.818-14.153,10.027-22.271c2.24-15.044-6.187-29.969-17.51-40.177
      c-28.483-25.679-73.116-26.422-108.534-11.588c-54.196,22.698-92.323,81.422-86.252,139.649
      c6.07,58.228,59.091,109.265,117.886,109.022c20.716-0.085,41.065-5.884,60.092-14.042c18.307-7.85,35.789-18.023,50.322-31.606
      c14.503-13.555,25.718-30.139,37.837-45.845c17.476-22.649,37.883-44.311,64.254-55.552c26.37-11.241,59.879-9.795,80.612,9.943
      c30.67,29.196,23.317,84.899,56.145,111.668c29.1,23.729,74.437,10.683,102.618-14.121c32.31-28.438,51.374-68.875,65.118-109.573
      c12.464-36.907,21.327-75.103,35.836-111.202" />
  </svg>
</div>

See the code in "Code Pen"

我希望通过在IE和Safari中运行来修复它。如果可能的话,请 仅限HTML5,CSS和SVG

1 个答案:

答案 0 :(得分:1)

Mozilla Devloper Network - SVG Animation - Browser Compatibility

  

Internet Explorer
  不支持

然后使用FakeSMIL

请参阅此FakeSmile with IE9

请参阅此http://jsfiddle.net/whyoz/c3wb5sbr/

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();
}

var svg   = document.getElementsByTagName('svg')[0];
.......
var animation = document.createElementNS(
    "http://www.w3.org/2000/svg", "animate");
.......
.......
registerAnimation(animation);
animation.beginElement();

可以在IE中为SVG带来动画

请参阅MSDN https://msdn.microsoft.com/en-us/library/gg193979(v=vs.85).aspx

示例 http://samples.msdn.microsoft.com/workshop/samples/svg/svgAnimation/basic/06seventeenGearsWith1Button.html