html(抽奖设计)

html 复制代码
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>抽奖</title>
		<style type="text/css">
			* {
				margin: 0;
				padding: 0;
			}
			.container {
				width: 800px;
				height: 800px;
				border: 1px dashed red;
				position: absolute;
				left: 50%;
				margin-left: -400px;
				text-align: center;
				line-height: 100px;
			}
			.container .box, .box2 {
				width: 300px;
				height: 300px;
				background: red;
				border-radius: 50%;
				margin: auto;
				margin-top: 50px;
				text-align: center;
				line-height: 300px;
			}
			.box2 {
				background: deepskyblue;
			}
			#show {
				font-size: 30px;
				color: white;
				font-weight: bold;
			}
			#start {
				width: 300px;
				height: 50px;
				background: palevioletred;
			}
		</style>
	</head>
	<body>
		<div class="container">
			<div class="box" id="box">
				<span id="show">
					奖品
				</span>
			</div>
			<button id="start" onclick="start()">开始抽奖</button>
			
		</div>
		
		<script type="text/javascript">
			
			var flag = false;
			var goods = ["香蕉", "地狱火", "八宝粥", "宝马五元代金券", "联想电脑", 
                         "iPhoneX", "1QB", "黄钻",'练习册','谢谢惠顾'];
			var show = document.getElementById("show");
			var _start = document.getElementById("start");
			var _box = document.getElementById("box")
			var timer;
			
			function start() {
				if (!flag) {
					flag = true;
					_start.innerHTML = "停止抽奖"
					timer = setInterval(function() {
						var index = Math.floor(Math.random()*goods.length);
						var good = goods[index]
						show.innerText = good;
						_box.className = "box2";
					}, 10)
				} else {
					flag = false;
					_start.innerHTML = "开始抽奖";
					clearInterval(timer);
//					_box["className"] = "box";
					_box.setAttribute("class", "box");
				}				
			}	
		</script>
	</body>
</html>

可以根据自己的喜好设计抽奖内容,或者修改颜色。

相关推荐
广州华水科技3 分钟前
单北斗GNSS在桥梁形变监测中的应用与技术进展分析
前端
我讲个笑话你可别哭啊5 分钟前
鸿蒙ArkTS快速入门
前端·ts·arkts·鸿蒙·方舟开发框架
CherryLee_12107 分钟前
基于poplar-annotation前端插件封装文本标注组件及使用
前端·文本标注
特立独行的猫a13 分钟前
C++轻量级Web框架介绍与对比:Crow与httplib
开发语言·前端·c++·crow·httplib
周航宇JoeZhou16 分钟前
JB2-7-HTML
java·前端·容器·html·h5·标签·表单
代码小库18 分钟前
【课程作业必备】Web开发技术HTML静态网站模板 - 校园动漫社团主题完整源码
前端·html
云计算DevOps-韩老师20 分钟前
HTML 中的行级元素(inline)、块级元素(block)、行内块元素(inline-block)
html
珹洺24 分钟前
Bootstrap-HTML(二)深入探索容器,网格系统和排版
前端·css·bootstrap·html·dubbo
BillKu25 分钟前
VS Code HTML CSS Support 插件详解
前端·css·html
xixixin_31 分钟前
【React】中 Body 类限定法:优雅覆盖挂载到 body 的组件样式
前端·javascript·react.js