优雅的加载动画

1,158 阅读3分钟

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

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

背景

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

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

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

优秀的加载动画特征

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

最终效果

垃圾桶加载动画.gif

一、添加 HTML 文件

  1. 最外层添加一个类名为 loaderJS_ondiv
  2. 里面添加两个类名为 binary 和一个类名为 getting-therespan
<div class="loader JS_on">
    <span class="binary"></span>
    <span class="binary"></span>
    <span class="getting-there">LOADING STUFF...</span>
</div>

二、添加 CSS 文件

  1. 设置 *box-sizing: border-box
  2. 设置 htmlbody 来使整个项目居中
* {
    box-sizing: border-box;
}
html,
body {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #2D4654;
}

主要的 CSS 代码

.loader {
    width: 130px;
    height: 170px;
    position: relative;
}

.loader::before,
.loader::after {
    content: "";
    width: 0;
    height: 0;
    position: absolute;
    bottom: 30px;
    left: 15px;
    z-index: 1;
    border-left: 50px solid transparent;
    border-right: 50px solid transparent;
    border-bottom: 20px solid #1b2a33;
    transform: scale(0);
    transition: all 0.2s ease;
}

.loader::after {
    border-right: 15px solid transparent;
    border-bottom: 20px solid #162229;
}

.loader .getting-there {
    width: 120%;
    text-align: center;
    position: absolute;
    bottom: 0;
    left: -7%;
    font-family: "Lato";
    font-size: 12px;
    letter-spacing: 2px;
    color: white;
}

.loader .binary {
    width: 100%;
    height: 140px;
    display: block;
    color: white;
    position: absolute;
    top: 0;
    left: 15px;
    z-index: 2;
    overflow: hidden;
}

.loader .binary::before,
.loader .binary::after {
    font-family: "Lato";
    font-size: 24px;
    position: absolute;
    top: 0;
    left: 0;
    opacity: 0;
}

.loader .binary:nth-child(1)::before {
    content: "0";
    animation: a 1.1s linear infinite;
}

.loader .binary:nth-child(1)::after {
    content: "0";
    animation: b 1.3s linear infinite;
}

.loader .binary:nth-child(2)::before {
    content: "1";
    animation: c 0.9s linear infinite;
}

.loader .binary:nth-child(2)::after {
    content: "1";
    animation: d 0.7s linear infinite;
}

.loader.JS_on::before,
.loader.JS_on::after {
    transform: scale(1);
}

@keyframes a {
    0% {
        transform: translate(30px, 0) rotate(30deg);
        opacity: 0;
    }

    100% {
        transform: translate(30px, 150px) rotate(-50deg);
        opacity: 1;
    }
}

@keyframes b {
    0% {
        transform: translate(50px, 0) rotate(-40deg);
        opacity: 0;
    }

    100% {
        transform: translate(40px, 150px) rotate(80deg);
        opacity: 1;
    }
}

@keyframes c {
    0% {
        transform: translate(70px, 0) rotate(10deg);
        opacity: 0;
    }

    100% {
        transform: translate(60px, 150px) rotate(70deg);
        opacity: 1;
    }
}

@keyframes d {
    0% {
        transform: translate(30px, 0) rotate(-50deg);
        opacity: 0;
    }

    100% {
        transform: translate(45px, 150px) rotate(30deg);
        opacity: 1;
    }
}

❤️ 感谢大家

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

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