分享一款html+css网页载入动画效果

效果演示

分享一款html+css网页载入动画效果-青鹿云

实现原理

  1. 通过2个伪元素来设置3条颜色边框
  2. 通过定位将3个圆弧边框层叠再一起,再通过旋转实现一个圆的效果
  3. 再给loading添加旋转动画即可
  4. 要实现文字转动的效果,只需让其反向旋转即可

实现代码

<div class="loading"> <span>loading...</span> </div>
@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;
}

完整代码

<!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>
© 版权声明
THE END
点赞389 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容