极客时间返利平台,你可以在上边通过山月的链接购买课程,并添加我的微信 (shanyue94) 领取返现。
山月训练营之面试直通车 服务上线了,从准备简历、八股文准备、项目经历准备、面试、面经、面经解答、主观问题答复、谈薪再到入职的一条龙服务。

# 如何实现一个 loading 动画

更多描述

如何实现一个 loading 动画,可用 css 或 svg

Issue

欢迎在 Gtihub Issue 中回答此问题: Issue 35 (opens new window)

svg 比较实在

# 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;
  }
}

transform 单词写错了吧

transform 单词写错了吧

应该是,随手写的,没留意拼写。

Author

回答者: 02220 (opens new window)

我直接 copy,把错的单词更改了也不效果

我直接 copy,把错的单词更改了也不效果

IDE 补全多填了些文字....你把 svg 和 circle 的 classname 改成 class 就好了

Author

回答者: 02220 (opens new window)

我直接 copy,把错的单词更改了也不效果

IDE 补全多填了些文字....你把 svg 和 circle 的 classname 改成 class 就好了

尴尬了,这么低级的错误

Author

回答者: hwb2017 (opens new window)

通过 svg 实现的简单 Loading 动画
https://codepen.io/hwb2017/pen/XWgNVyr

Author

回答者: Indusy (opens new window)

用的伪元素 https://codepen.io/indusy/pen/BaYmBXo

Last Updated: 6/26/2022, 10:48:10 AM