HTML下的点名

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<title></title>

<style>

*{

margin-left: 0px;

margin-top: 0px;

}

.container{

background-image: url(https://img.zcool.cn/community/01deac5b71220fa801206a3594899b.jpg@1280w_1l_2o_100sh.jpg);

background-color: aqua;

width: 1000px;

height: 480px;

border: 1px solid rgb(0, 255, 157);

position:absolute;

left: 50%;

margin-left: -500px;

text-align: center;

line-height: 100px;

margin-top: 150px;

}

.box,.box2{

width: 300px;

height: 300px;

background-image: url(https://img.chuapp.com/wp-content/uploads/2016/08/201608231471931218.gif?imageView2/2/w/700);

border-radius: 50%;

/* 水平位置居中 */

margin: auto;

margin-top: 50px;

text-align: center;

line-height: 300px

}

.box2{

background-color: blue;

}

#show{

font-size: 30px;

color: rgb(12, 14, 1);

font-weight: bolder;

}

#start{

width: 300px;

height: 50px;

background-color: rgb(0, 255, 170);

}

</style>

</head>

<body>

<div class="container">

<div class="box" id="box">

<span id="show">就决定是你了</span>

</div>

<button id="start" οnclick="change()">点名</button>

</div>

</body>

</html>

<script>

var flag = false

var awards = "张三","李四","王二狗","小黄毛","绿茶","细狗","周扒皮","狗剩"

var box = document.getElementById("box")

var show = document.getElementById("show")

var start = document.getElementById("start")

var timer

function change(){

if(!flag) {

flag = true

start.innerHTML="停止"

timer = setInterval(function(){

let index = Math.floor(Math.random()*awards.length)

show.innerHTML = awardsindex

box.setAttribute("class","box")

},10)

}else{

flag = false

start.innerHTML= "点名"

clearInterval(timer)

box.setAttribute("class","box")

}

}

</script>

相关推荐
CarIise5 分钟前
事件传播、CSS动画、服务器字体与jQuery
服务器·css·jquery
XLYcmy23 分钟前
HTML/CSS/JS 基础与 Vue 技术栈深度解析
java·前端·css·html·vue3·vue2·api
新知图书43 分钟前
12.3 智能体中Skill的约束与自进化实战
java·前端·数据库
风月说与山鬼1 小时前
四、Tailwind CSS——间距与尺寸
前端·css·tailwind css
en.en..1 小时前
C语言 static函数与头文件封装规范
java·c语言·前端
计算机魔术师1 小时前
旅途中用手机远程控制电脑?电脑不在身边,ToDesk/UU远程/TeamViewer移动端深度实测
前端
风月说与山鬼1 小时前
三、Tailwind CSS——排版与文字样式
前端·css·tailwind css
eokred1 小时前
图片预览组件的另一种设计:Headless、可组合、开箱即用
前端·react
南雨北斗1 小时前
解决web开发中前后端跨域通信(session失效问题)
前端