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>

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

相关推荐
JianZhen✓14 分钟前
面试题名词解析一
前端
会跑的葫芦怪17 分钟前
Web3开发中的前端、后端与合约:角色定位与协作逻辑
前端·web3·区块链
江城开朗的豌豆19 分钟前
TypeScript泛型:让类型也"通用"的魔法
前端·javascript
江城开朗的豌豆30 分钟前
TypeScript函数:给JavaScript函数加上"类型安全带"
前端·javascript
凌览31 分钟前
Node.js + Python 爬虫界的黄金搭档
前端·javascript·后端
Java 码农37 分钟前
vue 使用vueCli 搭建vue2.x开发环境,并且指定ts 和less
前端·vue.js·less
欧阳码农1 小时前
AI提效这么多,为什么不试试自己开发N个产品呢?
前端·人工智能·后端
chenbin___1 小时前
Omit<>的用法
开发语言·前端·javascript
嫂子的姐夫1 小时前
21-webpack介绍
前端·爬虫·webpack·node.js
IT_陈寒1 小时前
SpringBoot 3.x 中被低估的10个隐藏特性,让你的开发效率提升50%
前端·人工智能·后端