效果演示
这段 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 的关键帧动画,用于模拟加载器的步进效果。