前端常见的loading效果

文章展示了使用CSS实现的六种独特动画效果,包括无限循环的圆圈追逐,闪烁的圆点,高低起伏的音浪波形,左右交互的方圆变换,旋转的方块以及若隐若现的方块预加载效果。这些效果利用了CSS的关键帧动画和各种变换属性来创建动态视觉体验。
摘要由CSDN通过智能技术生成

1.无限循环圈圈

在这里插入图片描述

html

<div className={styles['chase-wrapper']}>
	<div className={styles['chase-item']}></div>
	<div className={styles['chase-item']}></div>
	<div className={styles['chase-item']}></div>
	<div className={styles['chase-item']}></div>
	<div className={styles['chase-item']}></div>
	<div className={styles['chase-item']}></div>
</div>

CSS(less写法)

.chase-wrapper {
    width: 60px;
    height: 60px;
    display: inline-block;
    animation: chase-loader 2.5s infinite linear both;
    margin-top: 25px;
    .chase-item {
        width: 100%;
        height: 100%;
        position: absolute;
        top: 0;
        left: 0;
        animation: chase-dot 2s infinite ease-in-out both;

        &::before {
            content: "";
            display: block;
            width: 25%;
            height: 25%;
            background-color: #4A90E2;
            border-radius: 100%;
            animation: chase-dot-before 2s infinite ease-in-out both;

        }

        &:nth-child(1) {
            animation-delay: -1.1s;

            &::before {
                animation-delay: -1.1s;
            }
        }

        &:nth-child(2) {
            animation-delay: -1s;

            &::before {
                animation-delay: -1s;
            }
        }

        &:nth-child(3) {
            animation-delay: -0.9s;

            &::before {
                animation-delay: -0.9s;
            }
        }

        &:nth-child(4) {
            animation-delay: -0.8s;

            &::before {
                animation-delay: -0.8s;
            }
        }

        &:nth-child(5) {
            animation-delay: -0.7s;

            &::before {
                animation-delay: -0.7s;
            }
        }

        &:nth-child(6) {
            animation-delay: -0.6s;

            &::before {
                animation-delay: -0.6s;
            }
        }
    }
}

@keyframes chase-loader {
    100% {
        transform: rotate(1turn);
    }
}

@keyframes chase-dot {

    80% {
        transform: rotate(360deg);

    }

    100% {
        transform: rotate(360deg);

    }
}

@keyframes chase-dot-before {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(0.4);
    }

    100% {
        transform: scale(1);

    }
}

普通CSS写法

.chase-wrapper {
  width: 60px;
  height: 60px;
  display: inline-block;
  animation: chase-loader 2.5s infinite linear both;
  margin: 50px;
}
.chase-item {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  animation: chase-dot 2s infinite ease-in-out both;
}
.chase-item:before {
  content: "";
  display: block;
  width: 25%;
  height: 25%;
  background-color: skyBlue;
  border-radius: 100%;
  animation: chase-dot-before 2s infinite ease-in-out both;
}

.chase-item:nth-child(1),
.chase-item:nth-child(1):before {
  animation-delay: -1.1s;
}
.chase-item:nth-child(2),
.chase-item:nth-child(2):before {
  animation-delay: -1s;
}
.chase-item:nth-child(3),
.chase-item:nth-child(3):before {
  animation-delay: -0.9s;
}
.chase-item:nth-child(4),
.chase-item:nth-child(4):before {
  animation-delay: -0.8s;
}
.chase-item:nth-child(5),
.chase-item:nth-child(5):before {
  animation-delay: -0.7s;
}
.chase-item:nth-child(6),
.chase-item:nth-child(6):before {
  animation-delay: -0.6s;
}

@keyframes chase-loader {
  100% {
    transform: rotate(1turn);
  }
}

@keyframes chase-dot {
  80%,
  100% {
    transform: rotate(360deg);
  }
}

@keyframes chase-dot-before {
  50% {
    transform: scale(0.4);
  }
  100%,
  0% {
    transform: scale(1);
  }
}

2. 一闪一闪的圆圈

在这里插入图片描述
html

<div class="pulse-wrapper">
    <div class="pulse-item one"></div>
    <div class="pulse-item two"></div>
    <div class="pulse-item three"></div>
</div>

css

.pulse-wrapper {
  margin: 50px;
}
.pulse-item {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background-color: skyBlue;
  animation: pulse-loader 0.4s ease 0s infinite alternate;
  position: relative;
  display: inline-block;
}
.two {
  margin: 0 15px;
  animation: pulse-loader 0.4s ease 0.2s infinite alternate;
}
.three {
  animation: pulse-loader 0.4s ease 0.4s infinite alternate;
}

@keyframes pulse-loader {
  0% {
    opacity: 1;
    transform: scale(1);
  }
  100% {
    opacity: 0.5;
    transform: scale(0.75);
  }
}

3.高低起伏的音浪

在这里插入图片描述
html

  <div class="rect-wrapper">
      <div class="rect-item rect1"></div>
      <div class="rect-item rect2"></div>
      <div class="rect-item rect3"></div>
      <div class="rect-item rect4"></div>
      <div class="rect-item rect5"></div>
  </div>

css

.rect-wrapper {
  margin: 50px;
}
.rect-item {
  width: 6px;
  height: 60px;
  background-color: skyBlue;
  display: inline-block;
  margin: 0 4px;
  animation: rect-loader 1.2s infinite ease-in-out;
}
.rect2 {
  animation-delay: -1.1s;
}
.rect3 {
  animation-delay: -1s;
}
.rect4 {
  animation-delay: -0.9s;
}
.rect5 {
  animation-delay: -0.8s;
}

@keyframes rect-loader {
  0%,
  40%,
  100% {
    transform: scaleY(0.4);
  }
  20% {
    transform: scaleY(1);
  }
}

4.左右交互的方圆

在这里插入图片描述
html

<div class="preloader-wrapper"></div>

css

.preloader-wrapper {
  position: relative;
  display: inline-block;
  width: 20px;
  height: 20px;
  margin: 50px;
}
.preloader-wrapper:before {
  width: 20px;
  height: 20px;
  border-radius: 20px;
  background: blue;
  content: "";
  position: absolute;
  background: #9b59b6;
  animation: preloader_before 2s infinite ease-in-out;
}

.preloader-wrapper:after {
  width: 20px;
  height: 20px;
  border-radius: 20px;
  background: blue;
  content: "";
  position: absolute;
  background: #2ecc71;
  left: 22px;
  animation: preloader_after 1.5s infinite ease-in-out;
}

@keyframes preloader_before {
  0% {
    transform: translateX(0px) rotate(0deg);
  }
  50% {
    transform: translateX(50px) scale(1.2) rotate(260deg);
    background: #2ecc71;
    border-radius: 0px;
  }
  100% {
    transform: translateX(0px) rotate(0deg);
  }
}
@keyframes preloader_after {
  0% {
    transform: translateX(0px);
  }
  50% {
    transform: translateX(-50px) scale(1.2) rotate(-260deg);
    background: #9b59b6;
    border-radius: 0px;
  }
  100% {
    transform: translateX(0px);
  }
}

5.闪转腾挪的方块

在这里插入图片描述
html

<div class="plane-wrapper"></div>

css

.plane-wrapper {
  width: 60px;
  height: 60px;
  background-color: skyBlue;
  display: inline-block;
  animation: plane-loader 1.2s infinite ease-in-out;
  margin: 50px;
}

@keyframes plane-loader {
  0% {
    transform: perspective(120px);
  }
  50% {
    transform: perspective(120px) rotateY(180deg);
  }
  100% {
    transform: perspective(120px) rotateY(180deg) rotateX(180deg);
  }
}

6.若隐若现的方块

在这里插入图片描述
html

<div class="cube-wrapper">
    <div class="cube cube1"></div>
    <div class="cube cube2"></div>
    <div class="cube cube3"></div>
    <div class="cube cube4"></div>
    <div class="cube cube5"></div>
    <div class="cube cube6"></div>
    <div class="cube cube7"></div>
    <div class="cube cube8"></div>
    <div class="cube cube9"></div>
</div>

css

.cube-wrapper {
  width: 60px;
  height: 60px;
  display: inline-block;
  margin: 50px;
}
.cube {
  width: 33%;
  height: 33%;
  float: left;
  background: skyBlue;
  animation: cube-loader 1.3s infinite ease-in-out;
  animation-delay: 0.2s;
}
.cube1 {
  animation-delay: 0.2s;
}
.cube2 {
  animation-delay: 0.3s;
}
.cube3 {
  animation-delay: 0.4s;
}
.cube4 {
  animation-delay: 0.1s;
}
.cube5 {
  animation-delay: 0.2s;
}
.cube6 {
  animation-delay: 0.3s;
}
.cube7 {
  animation-delay: 0s;
}
.cube8 {
  animation-delay: 0.1s;
}

@keyframes cube-loader {
  0%,
  70%,
  100% {
    transform: scale3D(1, 1, 1);
  }
  35% {
    transform: scale3D(0, 0, 1);
  }
}

地址
原文地址

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
页面加载loading逻辑是指在页面加载时,为了提高用户体验,通常需要显示一个加载动画,告知用户页面正在加载中。在前端实现中,通常需要考虑以下几个方面: 1. 加载动画的设计:加载动画的设计应该符合用户的视觉习惯,同时要简洁明了,不会影响用户对页面内容的阅读。可以使用 GIF 动画、SVG 动画等方式实现。在设计动画时,应该考虑到动画的大小、颜色、形状、速度等因素。 2. 加载动画的实现:加载动画的实现可以使用纯 CSSJavaScript 等方式。在纯 CSS 方式下,可以使用 CSS3 动画实现,例如使用 @keyframes 规则定义动画序列,然后使用 animation 属性将动画序列应用到元素上。在 JavaScript 方式下,可以使用 setTimeout 或 setInterval 函数实现动画的控制。需要注意的是,为了不阻塞页面的加载,应该将 JavaScript 代码尽量放在页面底部。 3. 加载动画的触发时机:加载动画的触发时机应该在页面开始加载后尽可能快地触发,同时应该在页面加载完成后及时隐藏。可以使用 window.onload 事件或者 $(document).ready() 函数来检测页面是否加载完成,然后触发加载动画的显示和隐藏。 4. 加载动画的性能优化:为了保证加载动画的流畅性,应该尽可能减少动画的复杂度和大小,避免使用过多的 CSS3 效果、图片等资源。同时,在加载动画的实现中,应该使用合适的算法和优化技巧来提高代码性能,例如缓存 DOM 对象、避免重绘等。 以上是实现页面加载loading逻辑的一些基本方面,具体实现方式还需要根据具体情况进行调整。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值