行动SVG动画,动画不起作用

时间:2014-10-22 23:08:51

标签: css css3 animation svg

我一直在关注教程,我无法弄清楚为什么线条动画不起作用,短划线偏移和短划线阵列似乎正在工作,但动画不是。

这里是js小提琴:http://jsfiddle.net/jp2ttb5L/5/

<style>
    .path {
      stroke-dasharray: 1000;
      stroke-dashoffset: 1000;
      animation: dash 5s linear forwards;
    }

    @keyframes dash {
      to {
        stroke-dashoffset: 0;
      }
    }
</style>

<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 18.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
     viewBox="0 0 1440 1080" enable-background="new 0 0 1440 1080" xml:space="preserve">

<g id="Layer_3">
    <polygon class="path" fill="none" stroke="#000000" stroke-width="4" stroke-linejoin="round" stroke-miterlimit="10" points="411.3,540.5 
        76.3,1043 411.3,1043 746.3,1043     "/>
    <polygon class="path" fill="none" stroke="#000000" stroke-width="4" stroke-linejoin="round" stroke-miterlimit="10" points="746.3,38.5 
        411.3,541 746.3,541 1081.2,541  "/>
    <polygon class="path" fill="none" stroke="#000000" stroke-width="4" stroke-linejoin="round" stroke-miterlimit="10" points="746.3,1043.5 
        411.3,541 746.3,541 1081.2,541  "/>
    <polygon class="path" fill="none" stroke="#000000" stroke-width="4" stroke-linejoin="round" stroke-miterlimit="10" points="1081.2,540.5 
        746.3,1043 1081.2,1043 1416.2,1043  "/>
</g>
</svg>

1 个答案:

答案 0 :(得分:0)

对于google Chrome和其他基于webkit的浏览器,您可以使用-webkit来解决此问题:

.path {
      stroke-dasharray: 1000;
      stroke-dashoffset: 1000;
      animation: dash 5s linear forwards;
      -webkit-animation: dash 5s linear forwards;
    }

    @keyframes dash {
      to {
        stroke-dashoffset: 0;
      }
    }
    @-webkit-keyframes dash {
      to {
        stroke-dashoffset: 0;
      }
    }