js实现页面动态加载效果(三个点)

实现方式:利用定时函数给div定时添加或去除背景色【记得引入jquery】
完整 代码如下:

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <meta charset="utf-8" />
    <style>
        .father {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%,-50%);
            width:32px;
            height:12px;
        }
        .son {
            float:left;
            border:1px solid #999;
            width:6px;
            height:6px;
            margin:1px;
            border-radius:50%;
        }
    </style>
</head>
<body id="MAX" style="background-color:white;">
    <div onclick="end()" style="width:20px;height:20px;background-color:#999;"></div>
    <div id="father" class="father">
        <div id="son1" class="son"></div>
        <div id="son2" class="son"></div>
        <div id="son3" class="son"></div>
        <div id="son4" class="son"style="display:none;border:unset;"></div>
    </div>
</body>
</html>
<script src="~/Scripts/jquery/jquery-2.1.1.min.js"></script>
<script>
    $(function () {
        jiazai();
    })
    function jiazai() {
        var t = 0;
        var timer = setInterval(function () {
            t++;
            if (t == 1) {
                document.getElementById("son" + t).style.backgroundColor = "#999";
                document.getElementById("son2").style.backgroundColor = "";
                document.getElementById("son3").style.backgroundColor = "";
            } else if (t == 2) {
                document.getElementById("son" + t).style.backgroundColor = "#999";
                document.getElementById("son1").style.backgroundColor = "";
                document.getElementById("son3").style.backgroundColor = "";
            } else if (t == 3) {
                document.getElementById("son" + t).style.backgroundColor = "#999";
                document.getElementById("son1").style.backgroundColor = "";
                document.getElementById("son2").style.backgroundColor = "";
            } else {
                document.getElementById("son3").style.backgroundColor = "";
            }
            if (t == 4) t = 0;
        }, 1000);
    }
    function end() {
        document.getElementById("father").style.display = "none";
        alert("加载结束");
    }
</script>

实现效果如下:
动态加载
完善:
1:每次修改背景色的时候可以修改大小,使用方法

document.getElementById("son3").style.height = "8px";
document.getElementById("son3").style.width= "8px";

2:去除小圆点的不边框。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值