<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>随机</title>
<!-- 在375px设备下1rem = 10px -->
<style>
html, body {
font-size: 0.26vw;
height: 100%;
margin: 0;
padding: 0;
}
.app {
font-size: 20px;
height: 4rem;
text-align:center;
color: #ff0000;
width: 20rem;
font-weight: 800;
}
.root {
color: #fff;
background-color: #1890FF;
border-color: #1890FF;
text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.12);
box-shadow: 0 2px 0 rgba(0, 0, 0, 0.045);
line-height: 1.6;
padding: 4px 15px;
position: relative;
display: inline-block;
font-weight: 400;
white-space: nowrap;
text-align: center;
background-image: none;
border: 1px solid transparent;
font-size: 14px;
border-radius: 4px;
}
.root:active {
outline: 0;
color: #fff;
background-color: #096dd9;
border-color: #096dd9;
}
.root:focus {
outline: 0;
color: #fff;
background-color: #40a9ff;
border-color: #40a9ff;
}
</style>
</head>
<body>
<div style="width: 100%; height: 100%; display: flex; align-items: center; justify-content: center">
<div>
<div class="app" id="app"></div>
<div style="text-align:center"><button class="root" id="root" onClick="random(1000)">开始</button></div>
</div>
</div>
<script>
document.getElementById('root').innerHTML = "开始";
let count = false;
let interVal = null;
function random(num){
count = !count;
if (count) {
interVal = setInterval(function(){ romdomArray(num) }, 100);
document.getElementById('root').innerHTML = "暂停";
} else {
document.getElementById('root').innerHTML = "开始";
clearInterval(interVal)
}
}
function romdomArray(num){
let array = [];
for (let i = 0; array.length < 5; i+=1) {
if (i===0) {
let rondomNumber = Math.round(Math.random()* num);
if (rondomNumber !== 0) {
array.push(Math.round(Math.random()* num));
}
} else {
let rondomNumber = Math.round(Math.random()* num);
if (array.indexOf(rondomNumber) === -1 && rondomNumber !== 0) {
array.push(rondomNumber);
}
}
}
document.getElementById('app').innerHTML = array.join(' ');
}
</script>
</body>
</html>
年会抽奖效果
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...