加载动画效果 HTML+ CSS

2021-08-16 15:30:12 浏览数 (2)

加载动画效果

写在前面

在无限的时间的河流里,人生仅仅是微小又微小的波浪。——郭小川

实现效果
实现原理
  1. 通过2个伪元素来设置3条颜色边框
  2. 通过定位将3个圆弧边框层叠再一起,再通过旋转实现一个圆的效果
  3. 再给loading添加旋转动画即可
  4. 要实现文字转动的效果,只需让其反向旋转即可
实现代码
HTML
代码语言:javascript复制
<div class="loading">
    <span>loading...</span>
</div>
CSS
代码语言:javascript复制
@keyframes rotate {
    100%{
        transform: rotateZ(360deg);
    }
}
@keyframes rotate_ni {
    100%{
        transform: rotateZ(-360deg);
    }
}
body {
    margin: 0;
    padding: 0;
    background-color: black;

}
.loading {
    position: relative;
    width: 200px;
    height: 200px;
    box-sizing: border-box;
    border-radius: 50%;
    border-top: 10px solid #74b9ff;
    animation: rotate 2s linear infinite;
    margin: 100px auto;
}
.loading::before,.loading::after {
    content: '';
    width: 200px;
    height: 200px;
    position: absolute;
    left: 0;
    top: -10px;
    box-sizing: border-box;
    border-radius: 50%;
}
.loading::before {
    border-top: 10px solid #a29bfe;
    transform: rotate(120deg);
}
.loading::after {
    border-top: 10px solid #55efc4 ;
    transform: rotate(240deg);
}
span {
    position: absolute;
    color: snow;
    width: 200px;
    height: 200px;
    text-align: center;
    line-height: 200px;
    animation: rotate_ni 2s linear infinite;
}
完整代码
代码语言:javascript复制
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        @keyframes rotate {
            100%{
                transform: rotateZ(360deg);
            }
        }
        @keyframes rotate_ni {
            100%{
                transform: rotateZ(-360deg);
            }
        }
        body {
            margin: 0;
            padding: 0;
            background-color: black;

        }
        .loading {
            position: relative;
            width: 200px;
            height: 200px;
            box-sizing: border-box;
            border-radius: 50%;
            border-top: 10px solid #74b9ff;
            animation: rotate 2s linear infinite;
            margin: 100px auto;
        }
        .loading::before,.loading::after {
            content: '';
            width: 200px;
            height: 200px;
            position: absolute;
            left: 0;
            top: -10px;
            box-sizing: border-box;
            border-radius: 50%;
        }
        .loading::before {
            border-top: 10px solid #a29bfe;
            transform: rotate(120deg);
        }
        .loading::after {
            border-top: 10px solid #55efc4 ;
            transform: rotate(240deg);
        }
        span {
            position: absolute;
            color: snow;
            width: 200px;
            height: 200px;
            text-align: center;
            line-height: 200px;
            animation: rotate_ni 2s linear infinite;
        }
    </style>
</head>
<body>
        <div class="loading">
            <span>loading...</span>
        </div>
</body>
</html>

本次的分享就到这里结束啦!

0 人点赞