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>

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

相关推荐
用户28907942162711 小时前
Spec-Kit应用指南
前端
酸菜土狗1 小时前
🔥 手写 Vue 自定义指令:实现内容区拖拽调整大小(超实用)
前端
ohyeah1 小时前
深入理解 React Hooks:useState 与 useEffect 的核心原理与最佳实践
前端·react.js
Cache技术分享1 小时前
275. Java Stream API - flatMap 操作:展开一对多的关系,拉平你的流!
前端·后端
apollo_qwe1 小时前
前端缓存深度解析:从基础到进阶的实现方式与实践指南
前端
周星星日记2 小时前
vue中hash模式和history模式的区别
前端·面试
Light602 小时前
Vue 高阶优化术:v-bind 与 v-on 的实战妙用与思维跃迁
前端·低代码·vue3·v-bind·组件封装·v-on·ai辅助开发
周星星日记2 小时前
5.为什么vue中使用query可以保留参数
前端·vue.js
lebornjose2 小时前
javascript - webgl中绑定(bind)缓冲区的逻辑是什么?
前端·webgl
瘦的可以下饭了2 小时前
Day05- CSS 标准流、浮动、Flex布局
前端