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>

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

相关推荐
!执行1 分钟前
遇到 Git 提示大文件无法上传确实让人头疼
前端·github
坚持学习前端日记26 分钟前
个人网站从零到盈利的成长策略
前端·程序人生
CamilleZJ39 分钟前
eslint+prettier
前端·eslint·工程化·prettier
web小白成长日记1 小时前
深入理解 React 中的 Props:组件通信的桥梁
前端·javascript·react.js
tjswk20081 小时前
在ios上动态插入元素的列表使用:last-child样式可能不能及时生效
前端
小小荧1 小时前
CSS 写 SQL 查询?后端慌了!
前端·sql
小高0071 小时前
🔥3 kB 换 120 ms 阻塞? Axios 还是 fetch?
前端·javascript·面试
千寻girling1 小时前
面试官 : “ Vue 选项式api 和 组合式api 什么区别? “
前端·vue.js·面试
小二·1 小时前
从零手写《超级玛丽》——前端 Canvas 游戏开发与物理引擎
前端·游戏
da_vinci_x1 小时前
【2D场景】16:9秒变21:9?PS “液态缩放” + AI 补全,零成本适配全面屏
前端·人工智能·游戏·aigc·设计师·贴图·游戏美术