实现方式:利用定时函数给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:去除小圆点的不边框。