简单抽奖机系统(中午吃什么?)

简单抽奖机系统(中午吃什么?)


#本来是写给我们宿舍的抽奖系统,因为纠结不知道每天中午到底吃什么,哈哈哈,希望大家先点赞收藏再借鉴哦!!

html和css部分:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
			 .box{
				 width: 800px;
				 height: 800px;
				 border: 1px solid red;
				 margin: auto;
				 text-align: center;
			 }
			 .box>div{
				 width: 300px;
				 height: 300px;
				 background-color: #87CEEB;
				 border-radius: 50%;
				 margin: auto;
				 line-height: 300px;
				 color: white;
				 font-size: 30px;
				 font-weight: bold;
				 margin-top: 50px;
			 }
			 .box >a{
				 text-decoration: none;
				 font-size: 20px;
				 display: inline-block;
				 background-image:linear-gradient(to right,skyblue,yellow) ;
				 width: 200px;
				 height: 50px;
				 border-radius: 20px;
				 line-height: 50px;
				 color: white;
				 margin: 30px;
				 
			 }
			 .bg-red{
				 background-color: #FF0000;
			 }
			 .bg-green{
				 background-color: greenyellow;
			 }
			 
		</style>
	</head>
	<body>
		<div class="box">
			<div class="content" id="content">奖品</div>
			<a href="#" onclick="run();" id="start">开始抽奖</a>
		</div>
		
		
	<script>
		//定义一个数组来存储奖品
		
		const goods=["麻辣烫","鱼粉","麻辣拌","干锅煎肉饭","波波鱼","螺蛳粉","砂锅","骨汤烩菜","新疆炒米粉","香锅","意面","米饭","三秦面","盖浇饭","椒麻鸡","粗粮面","武汉热干面","面皮","肉夹馍","后门鸡汤米线","胖阿姨卷饼"];
		let flag=true;
		let content=document.getElementById("content");
		let start=document.querySelector("#start");
		let timer;
		
		function run(){
			if(flag){
				flag=false;
				start.textContent="停止抽奖";
				// content.style.backgroundColor="red";
				
				content.className="bg-red";
				timer=window.setInterval(function (){
			//随机一个 0--goods.lengtj-1
			// let index=Math.random()*goods.length;
			let index=Math.floor(Math.random()*goods.length);
			let g=goods[index];
			content.textContent=g;
			},10);
			
			}else{
				flag=true;
				start.innerText="开始抽奖";
				content.className="bg-green";
				window.clearInterval(timer);
			}
			
		}
	
	
	
	</script>
	</body>
</html>

效果图展示:

在这里插入图片描述
在这里插入图片描述

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值