<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>点名器</title>
<style>
*{
margin:0;
padding: 0;
}
#box{
margin:200px auto;
width: 200px;
height: 200px;
position: relative;
color: #000;
background-color: pink;
}
p{
font-size: 20px;
height: 100%;
width: 100%;
text-align: center;
line-height: 200px;
}
#start,
#stop{
position: absolute;
width: 30px;
height: 30px;
background-color: red;
color: #fff;
bottom:0;
font-size: 12px;
text-align: center;
line-height: 30px;
border-radius: 5px;
}
#start{
left:0;
}
#stop{
right:0;
}
</style>
</head>
<body>
<div id="box">
<p id="cont">XXX</p>
<span id="start">start</span>
<span id="stop">stop</span>
</div>
<script>
var cont = document.getElementById('cont');
var start = document.getElementById('start');
var stop = document.getElementById('stop');
var arr = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23];
// alert(arr[33]);
var time = null;
start.onclick = function(){
// 每次点击之后,为了防止计时器叠加,需要清除上一次计时器
clearInterval(time);
var i = 0;
time = setInterval(rm,100);
function rm(){
cont.innerHTML = arr[(i++)%23];
}
}
stop.onclick = function(){clearInterval(time);}
</script>
</body>
</html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>点名器</title>
<style>
*{
margin:0;
padding: 0;
}
#box{
margin:200px auto;
width: 200px;
height: 200px;
position: relative;
color: #000;
background-color: pink;
}
p{
font-size: 20px;
height: 100%;
width: 100%;
text-align: center;
line-height: 200px;
}
#start,
#stop{
position: absolute;
width: 30px;
height: 30px;
background-color: red;
color: #fff;
bottom:0;
font-size: 12px;
text-align: center;
line-height: 30px;
border-radius: 5px;
}
#start{
left:0;
}
#stop{
right:0;
}
</style>
</head>
<body>
<div id="box">
<p id="cont">XXX</p>
<span id="start">start</span>
<span id="stop">stop</span>
</div>
<script>
var cont = document.getElementById('cont');
var start = document.getElementById('start');
var stop = document.getElementById('stop');
var arr = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23];
// alert(arr[33]);
var time = null;
start.onclick = function(){
// 每次点击之后,为了防止计时器叠加,需要清除上一次计时器
clearInterval(time);
var i = 0;
time = setInterval(rm,100);
function rm(){
cont.innerHTML = arr[(i++)%23];
}
}
stop.onclick = function(){clearInterval(time);}
</script>
</body>
</html>