环形加载动画

提示:流动的环形加载动画效果,css实现

前言


提示:以下是本篇文章的代码内容,供大家参考,相互学习

一、html代码

<!DOCTYPE html>
<html>

<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">

    <title>好看的加载动画效果</title>
    <link rel="stylesheet" href="../css.css">
</head>

<body>
    <div class="loading">
        <span>拼命加载中</span>
    </div>
</body>

</html>

二、css代码

*{
    /* 初始化 取消页面内外边距 */
    margin: 0;
    padding: 0;
}
body{
    /* 100%窗口高度 */
    height: 100vh;
    /* 渐变背景 */
    background: linear-gradient(to bottom,#2b5876,#09203f);
    /* 弹性布局 水平、垂直居中 */
    display: flex;
    justify-content: center;
    align-items: center;
}
.loading{
    width: 200px;
    height: 200px;
    box-sizing: border-box;
    border-radius: 50%;
    border-top: 10px solid #63a69f;
    /* 相对定位 */
    position: relative;
    /* 执行动画(动画a1 时长 线性的 无限次播放) */
    animation: a1 2s linear infinite;
}
.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 #f2e1ac;
    /* 旋转120度 */
    transform: rotate(120deg);
}
.loading::after{
    border-top: 10px solid #f2836b;
    /* 旋转240度 */
    transform: rotate(240deg);
}
.loading span{
    position: absolute;
    width: 200px;
    height: 200px;
    line-height: 200px;
    text-align: center;
    color: #fff;
    /* 执行动画(动画a2 时长 线性的 无限次播放) */
    animation: a2 2s linear infinite;
}

/* 定义动画 */
@keyframes a1{
    to{
        transform: rotate(360deg);
    }
}
@keyframes a2{
    to{
        transform: rotate(-360deg);
    }
}

总结

  1. 使用通配符选择器 * 来设置全局样式,这里用来取消页面内外边距(margin和padding)。

  2. 使用 linear-gradient 函数来设置渐变背景,可以设置渐变方向和颜色。

  3. 使用弹性布局(flexbox)来使元素水平垂直居中,可以通过 display: flexjustify-content: center 以及 align-items: center 来实现。

  4. 使用绝对定位(position: absolute)和相对定位(position: relative)来控制元素的位置。

  5. 使用 border-radius 属性设置圆角,可以使用百分比值来创建不同的圆角效果。

  6. 使用 box-sizing 属性来设置盒模型的大小,可以设置为 border-boxcontent-box,这里设置为 border-box

  7. 使用 animation 属性来定义动画,可以设置动画名称、时长、时间函数以及播放次数。

  8. 使用 @keyframes 规则来定义关键帧动画,可以在不同的关键帧中设置不同的样式,以创建不同的动画效果。

  9. 使用 transform 属性来设置元素的旋转、平移、缩放等变换效果。

  10. 使用 ::before::after 伪元素来创建元素的前后内容,可以使用 content 属性设置内容。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值