纯CSS实现117款常用的loading等待加载效果

5597次阅读 389人点赞 作者: WuBin 发布时间: 2022-09-15 10:46:31
扫码到手机查看

圆圈加载L1

可以直接查看全部案例:http://code.wubin.work/code/css/css-loading/


  <div class="com__box">
    <!-- loading -->
    <div class="loading"></div>
  </div>

.loading {
  width: 30px;
  height: 30px;
  border: 2px solid #000;
  border-top-color: transparent;
  border-radius: 100%;

  animation: circle infinite 0.75s linear;
}

@keyframes circle {
  0% {
    transform: rotate(0);
  }
  100% {
    transform: rotate(360deg);
  }
}

等待点点点L112


  <div class="com__box">
    <!-- loading -->
    <div class="loading">Loading</div>
  </div>

.loading {
  display: inline-block;
  color: #ddd;
  position: relative;
  font-size: 28px;
  font-family: Arial, Helvetica, sans-serif;
}

.loading::after {
  content: "";
  width: 3px;
  height: 3px;
  background: currentColor;
  position: absolute;
  bottom: 6px;
  right: -5px;
  animation: loading-animation 1s linear infinite;
}

@keyframes loading-animation {
  0% {
    box-shadow: 10px 0 rgba(255, 255, 255, 0), 20px 0 rgba(255, 255, 255, 0);
  }

  50% {
    box-shadow: 10px 0 #ddd, 20px 0 rgba(255, 255, 255, 0);
  }

  100% {
    box-shadow: 10px 0 #ddd, 20px 0 #ddd;
  }
}

转圈圈L2


  <div class="com__box">
    <!-- loading -->
    <div class="loading"></div>
  </div>

.loading {
  position: relative;
  width: 30px;
  height: 30px;
  border: 2px solid #000;
  border-top-color: rgba(0, 0, 0, 0.2);
  border-right-color: rgba(0, 0, 0, 0.2);
  border-bottom-color: rgba(0, 0, 0, 0.2);
  border-radius: 100%;

  animation: circle infinite 0.75s linear;
}

@keyframes circle {
  0% {
    transform: rotate(0);
  }
  100% {
    transform: rotate(360deg);
  }
}

点转圈L34


  <div class="com__box">
    <!-- loading -->
    <div class="loading">
      <div></div>
      <div></div>
      <div></div>
      <div></div>
      <div></div>
      <div></div>
      <div></div>
      <div></div>
    </div>
  </div>

.loading,
.loading > div {
  position: relative;
  box-sizing: border-box;
}

.loading {
  display: block;
  font-size: 0;
  color: #000;
}

.loading.la-dark {
  color: #333;
}

.loading > div {
  display: inline-block;
  float: none;
  background-color: currentColor;
  border: 0 solid currentColor;
}

.loading {
  width: 32px;
  height: 32px;
}

.loading > div {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 8px;
  height: 8px;
  margin-top: -4px;
  margin-left: -4px;
  border-radius: 100%;
  animation: ball-spin-clockwise 1s infinite ease-in-out;
}

.loading > div:nth-child(1) {
  top: 5%;
  left: 50%;
  animation-delay: -0.875s;
}

.loading > div:nth-child(2) {
  top: 18.1801948466%;
  left: 81.8198051534%;
  animation-delay: -0.75s;
}

.loading > div:nth-child(3) {
  top: 50%;
  left: 95%;
  animation-delay: -0.625s;
}

.loading > div:nth-child(4) {
  top: 81.8198051534%;
  left: 81.8198051534%;
  animation-delay: -0.5s;
}

.loading > div:nth-child(5) {
  top: 94.9999999966%;
  left: 50.0000000005%;
  animation-delay: -0.375s;
}

.loading > div:nth-child(6) {
  top: 81.8198046966%;
  left: 18.1801949248%;
  animation-delay: -0.25s;
}

.loading > div:nth-child(7) {
  top: 49.9999750815%;
  left: 5.0000051215%;
  animation-delay: -0.125s;
}

.loading > div:nth-child(8) {
  top: 18.179464974%;
  left: 18.1803700518%;
  animation-delay: 0s;
}

.loading.la-sm {
  width: 16px;
  height: 16px;
}

.loading.la-sm > div {
  width: 4px;
  height: 4px;
  margin-top: -2px;
  margin-left: -2px;
}

.loading.la-2x {
  width: 64px;
  height: 64px;
}

.loading.la-2x > div {
  width: 16px;
  height: 16px;
  margin-top: -8px;
  margin-left: -8px;
}

.loading.la-3x {
  width: 96px;
  height: 96px;
}

.loading.la-3x > div {
  width: 24px;
  height: 24px;
  margin-top: -12px;
  margin-left: -12px;
}

@keyframes ball-spin-clockwise {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }

  20% {
    opacity: 1;
  }

  80% {
    opacity: 0;
    transform: scale(0);
  }
}

使用base64图片背景作为加载

// 图片base64
data:image/gif;base64,R0lGODlhHgAeA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YNp5oia6iypot/MYHu8pZoAe2uPM9g643AhKPSCJgyewNmM2ktHeRXqrI6zWpxZ4ECdR2JZiWWSEAIfkEBQUAGQAsDwAHAA8AFQAABTVgJorYaJ4oppbouLJttsYmTN94Huw8TfC9nBA3GA4AwgVgKVwyTZfo6SkYSYVXXFZ7wXZRIQAh+QQFBQAZACwKAA4AFAAQAAAFPGAmjuSInWipjgKarnAszypBr0Rwl1Dg7yTfT5RQLQCD0pB0uYwAgJhg1CRBadVndJbVcp3WbawLzIBpIQAh+QQFBQAZACwGAA8AFgAPAAAFRGAmjmQpYmaqrmzrZmgpHK8Qi/ObJVivmz3f6HIxQQKEkjBDHBUAo0BgRSyKANDoNNUcYUlSbvea1XJLX/C2lf6RyqsQACH5BAUFABkALAMADwAUAA8AAAVAYCZajmieaKqubIternrNcYZlM11jeX3CqAEglcDcVEKTIWAyIgFDUYDZPJ6gp+nJecWatFurKPqlVl1g31cVAgAh+QQFBQAZACwAAAoAEwAUAAAFQGAmisJonqioIGnrvrB5zXRM31es77zI9BmAcCcc6oo9AIoQQGFczNHh+WI2RRiqK3DFalPcbiYLE4+/OjJQGwIAIfkEBQUAGQAsAAAFAA8AFwAABT5gJo4iQp6oiWZXil5wO1bCGq/vjZPw7v8rgHCIGw4LD6ByeWooA1AfNLqbAgMoAQaoHW1X2q8PI96Ry2ZUCAAh+QQJBQAZACwAAAIADwAXAAAFPmAmjuJFnuRloqzKour6jq4ojAAsi0Cf0ztcb0by/YiZwRHJRAae0BcUaog0r1iRoonpErveGZiJQZXJXFQIADs=
// 使用
.loading-bg{
  background-image: url('data:image/gif;base64,R...');
  background-repeat: no-repeat;
  background-position: center center;
}

相关资料

点赞 支持一下 觉得不错?客官您就稍微鼓励一下吧!
关键词:loading
推荐阅读
  • uniapp实现被浏览器唤起的功能

    当用户打开h5链接时候,点击打开app若用户在已经安装过app的情况下直接打开app,若未安装过跳到应用市场下载安装这个功能在实现上主要分为两种场景,从普通浏览器唤醒以及从微信唤醒。

    9603次阅读 623人点赞 发布时间: 2022-12-14 16:34:53 立即查看
  • Vue

    盘点Vue2和Vue3的10种组件通信方式

    Vue中组件通信方式有很多,其中Vue2和Vue3实现起来也会有很多差异;本文将通过选项式API组合式API以及setup三种不同实现方式全面介绍Vue2和Vue3的组件通信方式。

    4297次阅读 317人点赞 发布时间: 2022-08-19 09:40:16 立即查看
  • JS

    几个高级前端常用的API

    推荐4个前端开发中常用的高端API,分别是MutationObserver、IntersectionObserver、getComputedstyle、getBoundingClientRect、requ...

    14452次阅读 948人点赞 发布时间: 2021-11-11 09:39:54 立即查看
  • PHP

    【正则】一些常用的正则表达式总结

    在日常开发中,正则表达式是非常有用的,正则表达式在每个语言中都是可以使用的,他就跟JSON一样,是通用的。了解一些常用的正则表达式,能大大提高你的工作效率。

    13497次阅读 491人点赞 发布时间: 2021-10-09 15:58:58 立即查看
  • 【中文】免费可商用字体下载与考证

    65款免费、可商用、无任何限制中文字体打包下载,这些字体都是经过长期验证,经得住市场考验的,让您规避被无良厂商起诉的风险。

    12015次阅读 963人点赞 发布时间: 2021-07-05 15:28:45 立即查看
  • Vue

    Vue3开发一个v-loading的自定义指令

    在vue3中实现一个自定义的指令,有助于我们简化开发,简化复用,通过一个指令的调用即可实现一些可高度复用的交互。

    16376次阅读 1307人点赞 发布时间: 2021-07-02 15:58:35 立即查看
  • JS

    关于手机上滚动穿透问题的解决

    当页面出现浮层的时候,滑动浮层的内容,正常情况下预期应该是浮层下边的内容不会滚动;然而事实并非如此。在PC上使用css即可解决,但是在手机端,情况就变的比较复杂,就需要禁止触摸事件才可以。

    15187次阅读 1234人点赞 发布时间: 2021-05-31 09:25:50 立即查看
  • Vue

    Vue+html2canvas截图空白的问题

    在使用vue做信网单页专题时,有海报生成的功能,这里推荐2个插件:一个是html2canvas,构造好DOM然后转canvas进行截图;另外使用vue-canvas-poster(这个截止到2021年3月...

    29853次阅读 2347人点赞 发布时间: 2021-03-02 09:04:51 立即查看
  • Vue

    vue-router4过度动画无效解决方案

    在初次使用vue3+vue-router4时候,先后遇到了过度动画transition进入和退出分别无效的情况,搜遍百度没没找到合适解决方法,包括vue-route4有一些API都进行了变化,以前的一些操...

    25911次阅读 1994人点赞 发布时间: 2021-02-23 13:37:20 立即查看
交流 收藏 目录