# 如何实现一个 loading 动画
更多描述
如何实现一个 loading 动画,可用 css 或 svg
Issue
欢迎在 Gtihub Issue 中回答此问题: Issue 35 (opens new window)
Author
svg 比较实在
Author
# svg 实现方案
<svg classname="loading" viewbox="25 25 50 50">
<circle cx="50" cy="50" r="25" classname="path" fill="none" />
</svg>
.loading {
width: 50px;
height: 50px;
animation: rotate 2s linear 0s infinite;
}
.path {
animation: dash 2s ease-in-out infinite;
stroke: #00b390;
stroke-width: 2;
stroke-dasharray: 90 150;
stroke-dashoffset: 0;
stroke-linecap: round;
}
@keyframes rotate {
from {
tranform: rotate(0deg);
}
to {
tranform: rotate(360deg);
}
}
@keyframes dash {
0% {
stroke-dasharray: 1 150;
stroke-dashoffset: 0;
}
50% {
stroke-dasharray: 90 150;
stroke-dashoffset: -40px;
}
100% {
stroke-dasharray: 90 150;
stroke-dashoffset: -120px;
}
}
Author
transform 单词写错了吧
Author
transform 单词写错了吧
应该是,随手写的,没留意拼写。
Author
我直接 copy,把错的单词更改了也不效果
Author
我直接 copy,把错的单词更改了也不效果
IDE 补全多填了些文字....你把 svg 和 circle 的 classname 改成 class 就好了
Author
我直接 copy,把错的单词更改了也不效果
IDE 补全多填了些文字....你把 svg 和 circle 的 classname 改成 class 就好了
尴尬了,这么低级的错误
Author
通过 svg 实现的简单 Loading 动画
https://codepen.io/hwb2017/pen/XWgNVyr
Author
用的伪元素 https://codepen.io/indusy/pen/BaYmBXo