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. 设计模式 抽象工厂

    2024-07-15 03:10:04       48 阅读
  2. 设计模式:抽象工厂

    2024-07-15 03:10:04       50 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-15 03:10:04       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-15 03:10:04       72 阅读
  3. 在Django里面运行非项目文件

    2024-07-15 03:10:04       58 阅读
  4. Python语言-面向对象

    2024-07-15 03:10:04       69 阅读

热门阅读

  1. 常用设计模式

    2024-07-15 03:10:04       22 阅读
  2. Mybatis 传递数组给sql解析 解决not in失效问题

    2024-07-15 03:10:04       20 阅读
  3. sqlalchemy使用with_entities返回指定数据列

    2024-07-15 03:10:04       16 阅读
  4. Redis如何高效安全的遍历所有key

    2024-07-15 03:10:04       12 阅读
  5. ansible安装

    2024-07-15 03:10:04       18 阅读
  6. RocketMQ~生产者与消费者的消费模式(pull or push)

    2024-07-15 03:10:04       20 阅读
  7. Go语言基础数据类型、变量及自增语法

    2024-07-15 03:10:04       20 阅读
  8. Linux使用python调用串口<Ubuntu>

    2024-07-15 03:10:04       19 阅读