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>

相关推荐
敲敲了个代码3 小时前
从硬编码到 Schema 推断:前端表单开发的工程化转型
前端·javascript·vue.js·学习·面试·职场和发展·前端框架
dly_blog5 小时前
Vue 响应式陷阱与解决方案(第19节)
前端·javascript·vue.js
消失的旧时光-19435 小时前
401 自动刷新 Token 的完整架构设计(Dio 实战版)
开发语言·前端·javascript
console.log('npc')5 小时前
Table,vue3在父组件调用子组件columns列的方法展示弹窗文件预览效果
前端·javascript·vue.js
用户47949283569155 小时前
React Hooks 的“天条”:为啥绝对不能写在 if 语句里?
前端·react.js
我命由我123455 小时前
SVG - SVG 引入(SVG 概述、SVG 基本使用、SVG 使用 CSS、SVG 使用 JavaScript、SVG 实例实操)
开发语言·前端·javascript·css·学习·ecmascript·学习方法
用户47949283569156 小时前
给客户做私有化部署,我是如何优雅搞定 NPM 依赖管理的?
前端·后端·程序员
C_心欲无痕6 小时前
vue3 - markRaw标记为非响应式对象
前端·javascript·vue.js
qingyun9896 小时前
深度优先遍历:JavaScript递归查找树形数据结构中的节点标签
前端·javascript·数据结构
熬夜敲代码的小N7 小时前
Vue (Official)重磅更新!Vue Language Tools 3.2功能一览!
前端·javascript·vue.js