LOGO OA教程 ERP教程 模切知识交流 PMS教程 CRM教程 开发文档 其他文档  
 
网站管理员

常见的前端加载loading样式

freeflydom
2024年5月1日 7:48 本文热度 1954

前言

开发项目遇到需要添加前端loading样式的问题,遂想到参考一些成熟的解决方案。找到了UIverse网站Explore 3000+ Free UI Elements: CSS & Tailwind (uiverse.io)这个样式库,动手学习了几个常用的loading样式并进行了修改学习。 下面先放上各样式对应的html和css片段(均为MIT许可)。

样式预览及代码片段

  • 1. Loader by satyamchaudharydev

<div class="loader"></div>


.loader {
  display: block;
  --height-of-loader: 4px;
  --loader-color: #0071e2;
  width: 130px;
  height: var(--height-of-loader);
  border-radius: 30px;
  background-color: rgba(0,0,0,0.2);
  position: relative;
}


.loader::before {
  content: "";
  position: absolute;
  background: var(--loader-color);
  top: 0;
  left: 0;
  width: 0%;
  height: 100%;
  border-radius: 30px;
  animation: moving 1s ease-in-out infinite;
  ;
}


@keyframes moving {
  50% {
    width: 100%;
  }


  100% {
    width: 0;
    right: 0;
    left: unset;
  }
}


  • 2. Loader by milley69

<div class="loading">
  <svg width="64px" height="48px">
      <polyline points="0.157 23.954, 14 23.954, 21.843 48, 43 0, 50 24, 64 24" id="back"></polyline>
    <polyline points="0.157 23.954, 14 23.954, 21.843 48, 43 0, 50 24, 64 24" id="front"></polyline>
  </svg>
</div>


.loading svg polyline {
  fill: none;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}


.loading svg polyline#back {
  fill: none;
  stroke: #ff4d5033;
}


.loading svg polyline#front {
  fill: none;
  stroke: #ff4d4f;
  stroke-dasharray: 48, 144;
  stroke-dashoffset: 192;
  animation: dash_682 1.4s linear infinite;
}


@keyframes dash_682 {
  72.5% {
    opacity: 0;
  }


  to {
    stroke-dashoffset: 0;
  }
}


  • 3.  Loader by G4b413l

<div class="three-body">
<div class="three-body__dot"></div>
<div class="three-body__dot"></div>
<div class="three-body__dot"></div>
</div>


.three-body {
 --uib-size: 35px;
 --uib-speed: 0.8s;
 --uib-color: #5D3FD3;
 position: relative;
 display: inline-block;
 height: var(--uib-size);
 width: var(--uib-size);
 animation: spin78236 calc(var(--uib-speed) * 2.5) infinite linear;
}


.three-body__dot {
 position: absolute;
 height: 100%;
 width: 30%;
}


.three-body__dot:after {
 content: '';
 position: absolute;
 height: 0%;
 width: 100%;
 padding-bottom: 100%;
 background-color: var(--uib-color);
 border-radius: 50%;
}


.three-body__dot:nth-child(1) {
 bottom: 5%;
 left: 0;
 transform: rotate(60deg);
 transform-origin: 50% 85%;
}


.three-body__dot:nth-child(1)::after {
 bottom: 0;
 left: 0;
 animation: wobble1 var(--uib-speed) infinite ease-in-out;
 animation-delay: calc(var(--uib-speed) * -0.3);
}


.three-body__dot:nth-child(2) {
 bottom: 5%;
 right: 0;
 transform: rotate(-60deg);
 transform-origin: 50% 85%;
}


.three-body__dot:nth-child(2)::after {
 bottom: 0;
 left: 0;
 animation: wobble1 var(--uib-speed) infinite
    calc(var(--uib-speed) * -0.15) ease-in-out;
}


.three-body__dot:nth-child(3) {
 bottom: -5%;
 left: 0;
 transform: translateX(116.666%);
}


.three-body__dot:nth-child(3)::after {
 top: 0;
 left: 0;
 animation: wobble2 var(--uib-speed) infinite ease-in-out;
}


@keyframes spin78236 {
 0% {
  transform: rotate(0deg);
 }


 100% {
  transform: rotate(360deg);
 }
}


@keyframes wobble1 {
 0%,
  100% {
  transform: translateY(0%) scale(1);
  opacity: 1;
 }


 50% {
  transform: translateY(-66%) scale(0.65);
  opacity: 0.8;
 }
}


@keyframes wobble2 {
 0%,
  100% {
  transform: translateY(0%) scale(1);
  opacity: 1;
 }


 50% {
  transform: translateY(66%) scale(0.65);
  opacity: 0.8;
 }
}


  • 4. Loader by barisdogansutcu

<svg viewBox="25 25 50 50">
  <circle r="20" cy="50" cx="50"></circle>
</svg>


svg {
 width: 3.25em;
 transform-origin: center;
 animation: rotate4 2s linear infinite;
}


circle {
 fill: none;
 stroke: hsl(214, 97%, 59%);
 stroke-width: 2;
 stroke-dasharray: 1, 200;
 stroke-dashoffset: 0;
 stroke-linecap: round;
 animation: dash4 1.5s ease-in-out infinite;
}


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


@keyframes dash4 {
 0% {
  stroke-dasharray: 1, 200;
  stroke-dashoffset: 0;
 }


 50% {
  stroke-dasharray: 90, 200;
  stroke-dashoffset: -35px;
 }


 100% {
  stroke-dashoffset: -125px;
 }
}


  • 5. Loader by sahilxkhadka

<div class="relative flex w-64 animate-pulse gap-2 p-4">
  <div class="h-12 w-12 rounded-full bg-slate-400"></div>
  <div class="flex-1">
    <div class="mb-1 h-5 w-3/5 rounded-lg bg-slate-400 text-lg"></div>
    <div class="h-5 w-[90%] rounded-lg bg-slate-400 text-sm"></div>
  </div>
  <div class="absolute bottom-5 right-0 h-4 w-4 rounded-full bg-slate-400"></div>
</div>


作者:Zeworl_rod
链接:https://juejin.cn/post/7364404706918744105
来源:稀土掘金
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。



该文章在 2024/5/6 15:04:41 编辑过
点晴ERP是一款针对中小制造业的专业生产管理软件系统,系统成熟度和易用性得到了国内大量中小企业的青睐。
点晴PMS码头管理系统主要针对港口码头集装箱与散货日常运作、调度、堆场、车队、财务费用、相关报表等业务管理,结合码头的业务特点,围绕调度、堆场作业而开发的。集技术的先进性、管理的有效性于一体,是物流码头及其他港口类企业的高效ERP管理信息系统。
点晴WMS仓储管理系统提供了货物产品管理,销售管理,采购管理,仓储管理,仓库管理,保质期管理,货位管理,库位管理,生产管理,WMS管理系统,标签打印,条形码,二维码管理,批号管理软件。
点晴免费OA是一款软件和通用服务都免费,不限功能、不限时间、不限用户的免费OA协同办公管理系统。
Copyright 2010-2025 ClickSun All Rights Reserved