圆形加载动画

1,538 阅读3分钟

这是我参与8月更文挑战的第25天,活动详情查看:8月更文挑战

作者:battleKing
仓库:GithubCodePen
博客:CSDN掘金
反馈邮箱:myh19970701@foxmail.com
特别声明:原创不易,未经授权不得转载或抄袭,如需转载可联系笔者授权

背景

在用户心目中,优秀的应用、工具、网站都应该是制作精良且能快速响应他们需求的产品。以前我在发布一款产品的第一版时,登录验证的 loading... 延迟是 2-3秒,结果当天反馈邮箱就被用户挤爆了,大部分用户都认为这几秒是一个界面突然卡住是 软件BUG ,其实只是我们 验证登录信息 而已,所以如果没有 加载动画 告知用户我们在验证登录信息而只是让软件卡住不动的话,这是一种 非常不好的用户体验 ,虽然早期用户可能会给你的产品第二次机会,但绝大多数人对这款产品失去信息,不再使用,导致用户大量流失

解决方案:使用 加载动画,提供 即使反馈减少用户焦虑

加载动画分类进度条加载动画无限循环加载动画骨架图加载动画

优秀的加载动画特征

  1. 核心是 减少动画时间
  2. 给出 具体时间
  3. 告诉用户 为什么需要等待
  4. 让等待的过程不那么让人无聊 使用有趣的动画
  5. 减少用户等待时间的心理感知 色彩某个相关知识某条产品操作教学
  6. 透传公司品牌形象 公司理念公司价值观公司的标志吉祥物

最终效果

圆形加载动画.gif

一、添加 HTML 文件

  1. 最外层创建一个类名为 lds-defaultdiv
  2. 里面放置数个 div
<div class="lds-default">
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
</div>

二、添加 CSS 文件

先初始化页面

  1. 设置 *box-sizing: border-box
  2. 设置 body 来使整个项目居中
* {
    box-sizing: border-box;
}

body {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    margin: 0;
    background: #eaac83;
}

主要的 CSS 代码

.lds-default {
    display: inline-block;
    position: relative;
    width: 80px;
    height: 80px;
}

.lds-default div {
    position: absolute;
    width: 6px;
    height: 6px;
    background: #fff;
    border-radius: 50%;
    animation: lds-default 1.2s linear infinite;
}

.lds-default div:nth-child(1) {
    animation-delay: 0s;
    top: 37px;
    left: 66px;
}

.lds-default div:nth-child(2) {
    animation-delay: -0.1s;
    top: 22px;
    left: 62px;
}

.lds-default div:nth-child(3) {
    animation-delay: -0.2s;
    top: 11px;
    left: 52px;
}

.lds-default div:nth-child(4) {
    animation-delay: -0.3s;
    top: 7px;
    left: 37px;
}

.lds-default div:nth-child(5) {
    animation-delay: -0.4s;
    top: 11px;
    left: 22px;
}

.lds-default div:nth-child(6) {
    animation-delay: -0.5s;
    top: 22px;
    left: 11px;
}

.lds-default div:nth-child(7) {
    animation-delay: -0.6s;
    top: 37px;
    left: 7px;
}

.lds-default div:nth-child(8) {
    animation-delay: -0.7s;
    top: 52px;
    left: 11px;
}

.lds-default div:nth-child(9) {
    animation-delay: -0.8s;
    top: 62px;
    left: 22px;
}

.lds-default div:nth-child(10) {
    animation-delay: -0.9s;
    top: 66px;
    left: 37px;
}

.lds-default div:nth-child(11) {
    animation-delay: -1s;
    top: 62px;
    left: 52px;
}

.lds-default div:nth-child(12) {
    animation-delay: -1.1s;
    top: 52px;
    left: 62px;
}

@keyframes lds-default {

    0%,
    20%,
    80%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.5);
    }
}

❤️ 感谢大家

如果本文对你有帮助,就点个赞支持下吧,你的「赞」是我创作的动力。

如果你喜欢这篇文章的话,可以「点赞」 + 「收藏」 + 「转发」 给更多朋友。