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 的关键帧动画,用于模拟加载器的步进效果。
相关推荐
三小河1 分钟前
js Class中 静态属性和私有属性使用场景得的区别
前端·javascript
名字越长技术越强9 分钟前
CSS之选择器|弹性盒子模型
前端·css
hjt_未来可期28 分钟前
js实现复制、粘贴文字
前端·javascript·html
小帆聊前端32 分钟前
JS this取值深度解读
前端·javascript
videring34 分钟前
打字机效果-支持ckeditor5、框架无关
前端·javascript
tianxia34 分钟前
主项目通过iframe嵌套子项目,子项目弹框无法全屏
前端·javascript
Apeng_091944 分钟前
vue实现页面不断插入内容并且自动滚动功能
前端·javascript·vue.js
白狐_7981 小时前
【项目实战】我用一个 HTML 文件写了一个“CET-6 单词斩”
前端·算法·html
克喵的水银蛇2 小时前
Flutter 弹性布局实战:快速掌握 Row/Column/Flex 核心用法
开发语言·javascript·flutter
脾气有点小暴2 小时前
ES6(ECMAScript 2015)基本语法全解析
前端·javascript