HTML&CSS:玩趣升级!超有趣的跳一跳加载器

效果演示

这段 HTML 代码创建了一个简单的网页,其中包含一个动画效果,用来模拟一个加载器loading

HTML

html 复制代码
 <div class="loader"></div>
  • div创建了一个动画效果的加载器

CSS

css 复制代码
html, body {
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0;
    overflow: hidden;
    background: #212121;
}

.loader {
    position: relative;
    width: 120px;
    height: 90px;
    margin: 0 auto;
}

.loader:before {
    content: "";
    position: absolute;
    bottom: 30px;
    left: 50px;
    height: 30px;
    width: 30px;
    border-radius: 50%;
    background: #2a9d8f;
    animation: loading-bounce 0.5s ease-in-out infinite alternate;
}

.loader:after {
    content: "";
    position: absolute;
    right: 0;
    top: 0;
    height: 7px;
    width: 45px;
    border-radius: 4px;
    box-shadow: 0 5px 0 #f2f2f2, -35px 50px 0 #f2f2f2, -70px 95px 0 #f2f2f2;
    animation: loading-step 1s ease-in-out infinite;
}

@keyframes loading-bounce {
    0% {
        transform: scale(1, 0.7);
    }

    40% {
        transform: scale(0.8, 1.2);
    }

    60% {
        transform: scale(1, 1);
    }

    100% {
        bottom: 140px;
    }
}

@keyframes loading-step {
    0% {
        box-shadow: 0 10px 0 rgba(0, 0, 0, 0),
            0 10px 0 #f2f2f2,
            -35px 50px 0 #f2f2f2,
            -70px 90px 0 #f2f2f2;
    }

    100% {
        box-shadow: 0 10px 0 #f2f2f2,
            -35px 50px 0 #f2f2f2,
            -70px 90px 0 #f2f2f2,
            -70px 90px 0 rgba(0, 0, 0, 0);
    }
}

html, body:

  • width: 100vw: 宽度设置为视口宽度的100%。
  • height: 100vh: 高度设置为视口高度的100%。
  • display: flex: 使用 Flexbox 布局。
  • justify-content: center: 水平居中。
  • align-items: center: 垂直居中。
  • margin: 0: 移除外边距。
  • overflow: hidden: 隐藏溢出的内容。
  • background: #212121: 设置背景颜色为深灰色。

.loader: 定义加载器的样式。

  • position: relative: 相对定位。
  • width: 120px: 宽度为120像素。
  • height: 90px: 高度为90像素。
  • margin: 0 auto: 将加载器居中显示。

.loader:before: 创建圆点。

  • content: "": 伪元素的内容为空。
  • position: absolute: 绝对定位。
  • bottom: 30px: 距离底部30像素。
  • left: 50px: 距离左边50像素。
  • height: 30px: 高度为30像素。
  • width: 30px: 宽度为30像素。
  • border-radius: 50%: 圆形。
  • background: #2a9d8f: 背景颜色为绿色。
  • animation: loading-bounce 0.5s ease-in-out infinite alternate: 应用动画效果。

.loader:after: 创建加载器阴影。

  • content: "": 伪元素的内容为空。
  • position: absolute: 绝对定位。
  • right: 0: 靠右对齐。
  • top: 0: 顶部对齐。
  • height: 7px: 高度为7像素。
  • width: 45px: 宽度为45像素。
  • border-radius: 4px: 圆角。
  • box-shadow: 创建多个阴影效果,模拟加载器的动画效果。
  • animation: loading-step 1s ease-in-out infinite: 应用动画效果。

动画

  • @keyframes loading-bounce: 定义一个名为 loading-bounce 的关键帧动画,用于模拟弹跳效果。
  • @keyframes loading-step: 定义一个名为 loading-step 的关键帧动画,用于模拟加载器的步进效果。
相关推荐
翼帆2 分钟前
我用 AI 复刻了 CodeTank,重温代码坦克
前端·javascript·开源·ai编程·游戏开发·codetank
黑土豆2 小时前
用 drawink 给业务页面加一层画板:从网页批注到无限板书
前端·javascript·github
jianqiang.xue16 小时前
Espressif-IDE进入维护模式:乐鑫把ESP32开发的宝押给VS Code
前端·css·ide
feixing_fx17 小时前
CSS 变量(Custom Properties):构建可扩展的主题切换系统
前端·css·前端框架·html·css3
Hilaku21 小时前
Claude Code 过夜跑长任务实战:tmux、权限、验收,以及我为什么换到 ApexOne
前端·javascript·程序员
程序员大阳21 小时前
副队长ES6+教程(14)--手写Promise来加深理解
前端·javascript·es6·源码·promise·手写·深层
程序员大阳21 小时前
副队长ES6+教程(11)--生成器 Generator
javascript·es6·生成器·generator
FungLeo1 天前
成为全栈·Vue 管理后台篇·可折叠侧栏与移动抽屉:后台导航的响应式实现
前端·javascript·vue.js·侧边栏·响应式布局·无障碍·移动端导航
程序员大阳1 天前
副队长ES6+教程(9)--Set 与 Map
javascript·es6·set·map·for of遍历
zhanlang02171 天前
HTML 零基础入门到企业实战【第七章 表单标签|7.1 表单核心作用:数据收集、用户交互原理】
前端·html·交互