圆盘闪烁效果

效果图
圆盘闪烁

html代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<style>
    .lottery {
        position: relative;
        width: 400px;
        height: 400px;
        border-radius:50%;
        background: #B7E4F9;
    }
    .dot {
        position: absolute;
        left: 50%;
        top:50%;
        width: 20px;
        height: 20px;
        margin-left:-10px;
        margin-top: -10px;
        border-radius: 50%;
        background: #FFEC7E;
    }
    .glitter {
        background: #fff;
    }
</style>
<body>
<script>
    (function(){
        var body = document.body
        var divLottery = document.createElement('div');
        var counter = 0;
        divLottery.className = "lottery";
        createDot(12);
        body.appendChild(divLottery);
        //创建小圆点
        function createDot(n){
            if(n%2!==0) throw new Error("n必须是正偶数")
            for(var i=0;i<n;i++){
                var span = document.createElement('span');
                span.className = 'dot '+ 'dot'+i;
                span.style.transform = `rotate(${360/n*i}deg) translateY(-170px)`;
                divLottery.appendChild(span);
            }
        }
        //小圆点闪烁
        function glitter(n){
            var even = document.querySelectorAll(`.dot:nth-child(2n)`);
            var odd = document.querySelectorAll(`.dot:nth-child(2n+1)`);
            if(n%2==0){
                even.forEach(function(val){
                    val.classList.add('glitter');
                })
                odd.forEach(function(val){
                    val.classList.remove('glitter');
                })
            }else{
                odd.forEach(function(val){
                    val.classList.add('glitter');
                })
                even.forEach(function(val){
                    val.classList.remove('glitter');
                })
            }
        }
        setInterval(function () {
            glitter(counter);
            counter++;
        }, 500);
    })()
</script>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值