温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

CSS3如何实现loading预加载动画特效

发布时间:2021-10-15 14:01:25 阅读:219 作者:小新 栏目:web开发
前端开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

小编给大家分享一下CSS3如何实现loading预加载动画特效,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

该loading特效共有4种不同的效果,分别通过不同的CSS3 keyframes帧动画来完成。

CSS3如何实现loading预加载动画特效

HTML结构

4种loading预加载动画的HTML结构分别如下:

<!-- 效果一 -->
<div class="spinner-box">
  <div class="circle-border">
    <div class="circle-core"></div>
  </div>  
</div>
 
<!-- 效果二 -->
<div class="spinner-box">
  <div class="configure-border-1">  
    <div class="configure-core"></div>
  </div>  
  <div class="configure-border-2">
    <div class="configure-core"></div>
  </div> 
</div>
 
<!-- 效果三 -->
<div class="spinner-box">
  <div class="pulse-container">  
    <div class="pulse-bubble pulse-bubble-1"></div>
    <div class="pulse-bubble pulse-bubble-2"></div>
    <div class="pulse-bubble pulse-bubble-3"></div>
  </div>
</div>
 
<!-- 效果四 -->
<div class="spinner-box">
  <div class="solar-system">
    <div class="earth-orbit orbit">
      <div class="planet earth"></div>
      <div class="venus-orbit orbit">
        <div class="planet venus"></div>
        <div class="mercury-orbit orbit">
          <div class="planet mercury"></div>
          <div class="sun"></div>
        </div>
      </div>
    </div>
  </div>
</div>

CSS样式

然后分别为它们添加下面的CSS样式。

/* KEYFRAMES */
 
@keyframes spin {
  from {
    transformrotate(0);
  }
  to{
    transformrotate(359deg);
  }
}
 
@keyframes configure-clockwise {
  0% {
    transformrotate(0);
  }
  25% {
    transformrotate(90deg);
  }
  50% {
    transformrotate(180deg);
  }
  75% {
    transformrotate(270deg);
  }
  100% {
    transformrotate(359deg);
  }
}
 
@keyframes configure-xclockwise {
  0% {
    transformrotate(45deg);
  }
  25% {
    transformrotate(-45deg);
  }
  50% {
    transformrotate(-135deg);
  }
  75% {
    transformrotate(-215deg);
  }
  100% {
    transformrotate(-305deg);
  }
}
 
@keyframes pulse {
  from {
    opacity1;
    transformscale(1);
  }
  to {
    opacity: .25;
    transformscale(.75);
  }
}
 
/* GRID STYLING */
 
* {
  box-sizing: border-box;
}
 
body {
  min-height100vh;
  background-color#37474f;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  align-items: flex-start;
}
 
.spinner-box {
  width300px;
  height300px;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: transparent;
}
 
/* SPINNING CIRCLE */
 
.circle-border {
  width150px;
  height150px;
  padding3px;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius50%;
  backgroundrgb(63,249,220);
  backgroundlinear-gradient(0degrgba(63,249,220,0.133%rgba(63,249,220,1100%);
  animation: spin .8s linear 0s infinite;
}
 
.circle-core {
  width100%;
  height100%;
  background-color#37474f;
  border-radius50%;
}
 
/* X-ROTATING BOXES */
 
.configure-border-1 {
  width115px;
  height115px;
  padding3px;
  position: absolute;
  display: flex;
  justify-content: center;
  align-items: center;
  background#ffab91;
  animation: configure-clockwise 3s ease-in-out 0s infinite alternate;
}
 
.configure-border-2 {
  width115px;
  height115px;
  padding3px;
  left: -115px;
  display: flex;
  justify-content: center;
  align-items: center;
  backgroundrgb(63,249,220);
  transformrotate(45deg);
  animation: configure-xclockwise 3s ease-in-out 0s infinite alternate;
}
 
.configure-core {
  width100%;
  height100%;
  background-color#37474f;
}
 
/* PULSE BUBBLES */
 
.pulse-container {
  width120px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
 
.pulse-bubble {
  width20px;
  height20px;
  border-radius50%;
  background-color#3ff9dc;
}
 
.pulse-bubble-1 {
    animation: pulse .4s ease 0s infinite alternate;
}
.pulse-bubble-2 {
    animation: pulse .4s ease .2s infinite alternate;
}
.pulse-bubble-3 {
    animation: pulse .4s ease .4s infinite alternate;
}
 
/* SOLAR SYSTEM */
 
.solar-system {
  width250px;
  height250px;
  display: flex;
  justify-content: center;
  align-items: center;
}
 
.orbit {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    border1px solid #ffffffa5;
    border-radius50%;
}
 
.earth-orbit {
    width165px;
    height165px;
  -webkit-animation: spin 12s linear 0s infinite;
}
 
.venus-orbit {
    width120px;
    height120px;
  -webkit-animation: spin 7.4s linear 0s infinite;
}
 
.mercury-orbit {
    width90px;
    height90px;
  -webkit-animation: spin 3s linear 0s infinite;
}
 
.planet {
    position: absolute;
    top: -5px;
  width10px;
  height10px;
    border-radius50%;
  background-color#3ff9dc;
}
 
.sun {
    width35px;
    height35px;
    border-radius50%;
    background-color#ffab91;
}

以上是“CSS3如何实现loading预加载动画特效”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

原文链接:http://blog.itpub.net/69901074/viewspace-2633681/

AI

开发者交流群×