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 = awards[index]

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

},10)

}else{

flag = false

start.innerHTML= "点名"

clearInterval(timer)

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

}

}

</script>

相关推荐
kura_tsuki5 分钟前
[Web网页] LAMP 架构与环境搭建
前端·架构
yinuo13 分钟前
UniApp+Vue3多分包引入同一 npm 库被重复打包至 vendor 的问题分析与解决
前端
码界奇点25 分钟前
Spring Web MVC构建现代Java Web应用的基石
java·前端·spring·设计规范
yinuo44 分钟前
UniApp + Vue3 使用 marked 报错:SyntaxError /[\p{L}\p{N}]/u 问题分析与解决
前端
大前端helloworld1 小时前
前端梳理体系从常问问题去完善-框架篇(Vue2&Vue3)
前端·javascript·面试
小墨宝2 小时前
web前端学习LangGraph
前端·学习
南囝coding2 小时前
React 19.2 重磅更新!这几个新特性终于来了
前端·react.js·preact
Dajiaonew2 小时前
Vue3 + TypeScript 一篇文章 后端变全栈
前端·javascript·typescript
广州华水科技2 小时前
GNSS与单北斗变形监测一体机在基础设施安全中的应用分析
前端
勤劳打代码3 小时前
妙笔生花 —— Flutter 实现飞入动画
前端·flutter·设计模式