css3实现加载进度条的效果(二)

css3实现光效加载的进度条,下面来看实现方法!
请添加图片描述

 	<div class="progress-bar orange shine">
        <span id="blue"></span>
    </div>

主要的css代码

.progress-bar {
            width: 350px;
            background-color: #1a1a1a;
            height: 35px;
            margin: 70px auto 0;
            padding: 5px;
            border-radius: 5px;
            box-shadow: 0 1px 5px #000 inset, 0 1px 0 #444;
        }

        .progress-bar span {
            display: inline-block;
            height: 100%;
            border-radius: 3px;
            box-shadow: 0 1px 0 rgba(255, 255, 255, .5) inset;
            transition: width .4s ease-in-out;

        }

实现橙色bar的光效

      .orange span {
            background-color: #fecf23;
            background-image: linear-gradient(top, #fecf23, #fd9215);
            text-align: center;
            line-height: 2;
            color: #fff;
        }


        .shine span {
            position: relative;
        }

        .orange span::after {
            content: '';
            opacity: 0;
            position: absolute;
            top: 0;
            right: 0;
            bottom: 0;
            left: 0;
            background: #fff;
            border-radius: 3px;
            animation: animate-shine 2s ease-out infinite;
        }

关键的动画代码

      @keyframes animate-shine {
            0% {
                opacity: 0;
                width: 0;
            }

            50% {
                opacity: .5;
            }

            100% {
                opacity: 0;
                width: 95%;
            }
        }

进度百分比的实现

let dom = document.getElementById('blue')
            let w = 100;

            let timer = setInterval(() => {
                if (w < 350) {
                    w += 1;
                    dom.innerHTML = Math.floor(w / 350 * 100) + '%'
                    dom.style.width = w + "px"
                } else {
                    alert("加载完毕")
                    clearInterval(timer)
                }
            }, 100)

至此就实现了一个光效的进度条!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值