Why this CSS3 animation doesn't work in MS Edge or IE11?

空扰寡人 提交于 2019-12-02 01:29:24

Even though MSDN says that as of MS Edge the stroke-dashoffset property is animatable with CSS animations and transitions, it still doesn't work for some reason. If we re-create this animation using stroke-dasharray instead of stroke-dashoffset then it works as expected in Edge.

But it will still not work in IE11 or lower because again as indicated in MSDN, the stroke-dasharray is animatable using CSS animations and transitions only from MS Edge.

The modified animation still works in latest versions of Chrome, Firefox and Opera.

#my-circle {
  stroke: blue;
  stroke-dasharray: 1100;
  stroke-dashoffset: 0;
  animation: draw-first-shape 1s forwards 3;
}
@keyframes draw-first-shape {
  from {
    stroke-dasharray: 0, 1100;
  }
  to {
    stroke-dasharray: 1100, 1100;
  }
}
<svg xmlns="http://www.w3.org/2000/svg" width="500" height="300" viewBox="0 0 500.00001 300" id="svg2">
  <g id="layer1" transform="translate(0 -752.362)">
    <ellipse id="my-circle" cx="257.013" cy="907.735" rx="201.742" ry="111.465" fill="#fff" stroke="#007400" stroke-width="3" />
  </g>
</svg>

As a workaround for MS Edge, you can animate stroke-width (making a tiny variation of its value) together with stroke-dashoffset. For instance, in the case of the question:

@keyframes draw-first-shape {
    from {
        stroke-dashoffset: 1100;
        stroke-width: 3.03;
    }
    to {
        stroke-dashoffset: 0;
        stroke-width: 3;
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!