html - SVG 连续线加载器动画
问题描述
我有以下 SVG 行:
svg#line_loader {
position: relative; float: left; clear: none; display: block;
width: 100%; height: 8px; margin: 0; padding: 0;
stroke: rgb(255, 205, 0);
stroke-width: 10; stroke-linecap: round;
stroke-dasharray: 100;
stroke-dashoffset: 0;
animation: dash 1s linear forwards infinite;
}
@keyframes dash {
0% { stroke-dashoffset: 0; }
100% { stroke-dashoffset: 100; }
}
<svg id="line_loader"><line x1="100%" y1="0%" x2="0%" y2="0%"></line></svg>
然而,动画最终看起来参差不齐。
看看:jsFiddle
解决方案
您需要每次迭代都以相同的起始位置结束。这意味着偏移量应该是100%
,并且破折号应该是容器宽度的百分比:
svg#line_loader {
position: relative; clear: none; display: block;
width: 100%; height: 8px; margin: 0; padding: 0;
stroke: rgb(255, 205, 0);
stroke-width: 10; stroke-linecap: round;
stroke-dasharray: 25%;
animation: dash 1s linear forwards infinite;
}
@keyframes dash {
0% { stroke-dashoffset: 0; }
100% { stroke-dashoffset: 100%; }
}
<svg id="line_loader"><line x1="100%" y1="0%" x2="0%" y2="0%"></line></svg>
推荐阅读
- node.js - 与 express 一起使用时,socketio 中的错误可能是什么?
- angular - TypeScript 中的数组为空
- ios - 如何在“等待开发者发布”状态下访问 IPA 文件?
- javascript - 有没有办法在继续之前等待承诺?
- django - 如何让谷歌云存储保存重复文件而不覆盖
- excel - 如何仅将用逗号“,”分隔的图像 url 列表中的第一个 url 粘贴到 Excel 中的另一个单元格
- javascript - 浏览器 (Chrome) 上的缓存文件 (css, js) 只包含 html
- apache-kafka - kafka + confluent control center + 如何获取非企业版
- list - 将嵌套的字典列表转换为 Ansible 中的字典
- mysql - 使用 INSERT INTO 和 SELECT 将不同表中的不同行添加到另一个表中