<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
div {
width: 70px;
height: 70px;
background-color: red;
border-radius: 50%;
margin-left: 10px;
margin-top: 10px;
color: yellow;
text-align: center;
font-size: 25px;
line-height: 70px;
}
button {
width: 90px;
height: 30px;
margin-left: 30px;
margin-top: 10px;
}
section {
display: flex;
}
</style>
</head>
<body>
<button>开始</button>
<button>停止</button>
<section>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</section>
<script>
var btn = document.querySelectorAll('button')
var div = document.querySelectorAll('div')
var sec = document.querySelector('section')
var n = 0
var count = 0
var timer = null
// var timer1 = null
btn[0].onclick = function () {
if (n >= 7) {
n = 0
}
clearInterval(timer)
timer = setInterval(function () {
for (var i = n; i < div.length; i++) {
count = parseInt(Math.random() * 30);
div[i].innerText = count
}
}, 30)
}
btn[1].onclick = function () {
setTimeout(function () {
n++
if (n >= 7) {
clearInterval(timer)
}
}, 500)
}
</script>
</body>
</html>
简易彩票小游戏(逐个停止)
最新推荐文章于 2022-08-13 16:52:11 发布