1.先在html中创建svg元素
<svg height="60" width="160"></svg>
2.在svg里面添加矩形元素rect
<rect id="shape" height="60" width="160"/>
3.添加css描边动画
// stroke-dasharray:第一个数值是实线长度,第二个数值是间隙长度
// stroke-dashoffset:是描边线的偏移量(正值:左上角逆时针偏移量;负值:左上角顺时针偏移量)
// stroke-width:描线宽度
// fill:矩形填充色
// stroke:描线颜色
<style>
@keyframes lineAnimate {
0% {
stroke-dasharray: 100 120;
stroke-dashoffset: 20;
}
100% {
stroke-dasharray: 100 120;
stroke-dashoffset: -200;
}
}
#shape {
stroke-width: 6px;
fill: transparent;
stroke: #009FFD;
animation: lineAnimate 3s infinite;
}