准备工具:Adobe AI+PSjavascript
九、CSS3 SVG描边动画及实现原理,依赖两个属性stroke-dasharray和stroke-dashoffset
stroke-dasharray 表示虚线描边。可选值为:none, dasharray, inherit. 其中,none表示不是虚线;dasharray为一个逗号或空格分隔的数值列表。表示各个虚线端的长度。能够是固定的长度值,也能够是百分比值;inherit表继承。
stroke-dashoffset 表示虚线的起始偏移。可选值为:percentage, length, inherit. 百分比值,长度值,继承。
原理就是将描边设置虚线,stroke-dasharray的数值与路径长度一致或者大于路径长度便可,需尝试肯定,路径长的话就给个大点的值,路径短就给个小点的值,效果满意便可。
而后再设置路径的偏移量stroke-dashoffset与stroke-dasharray的值同样的大便可,而后添加定义好的动画,将偏移量从样式中设置好的数值过渡到0,就实现了描边的效果。java
/**********SVG描边动画**********/ @include keyframes(dash, webkit moz ms spec){ to { stroke-dashoffset: 0; } } /**********SVG描边动画**********/
path,rect{ stroke-dasharray: 400; stroke-dashoffset: 400; @include animation(dash 1.5s ease-in-out 1); &.p-long{ stroke-dasharray: 2000; stroke-dashoffset: 2000; @include animation(dash 1.5s ease-in-out 1); } }
十、描边效果web