使用js和css实现抽奖网页小程序

该文章展示了一个使用HTML、CSS和JavaScript编写的抽奖小程序代码。用户点击开始按钮后,程序将从预定义的奖品列表中随机选择一个显示在页面上。当用户点击停止按钮时,抽奖会暂停。这个小程序可以用于简单的互动活动或演示目的。
摘要由CSDN通过智能技术生成
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>抽奖小程序</title>
		<style>
			#container{
				width: 300px;
				height: 300px;
				margin-top: 80px;
				margin-left: 43%;
				font-size: 20px;
				background-color:;
			}
			#box{
				width: 300px;
				height: 100px;
				box-shadow: 2px;
				text-align: center;
				border: solid 2px ;
				background-color: antiquewhite;
			}
			#bt{
				
				width: 300px;
				height: 100px;
				box-shadow: 2px;
				text-align: center;
				border: solid 2px ;
				 background-color: rgb(82, 83, 170);
			}
			
		</style>
	</head>
	<body>
		<div id="container">
		<div id="box">开始抽奖</div>
		<div id="bt" onclick="doit()">
			停止抽奖
		</div>
		</div>
	</body>
	<script>
		var nameList = ["华为","苹果","小米","vivo","oppo","荣耀","三星","索尼","一加"];
		var mytime =null;
		function doit(){
			var bt =document.getElementById("bt");
			if(mytime==null){
				bt.innerHTML = "停止抽奖";
				show();
			}
			else{
				bt.innerHTML = "开始抽奖";
				clearInterval(mytime);
				mytime=null;
			}
		}
		function show(){
			var box =document.getElementById("box");
			var num =Math.floor(Math.random() *10000)%  nameList.length;
			box.innerHTML = nameList[num];
			mytime = setTimeout("show()",1);
		}
		
	</script>
</html>

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

哎呦☞ᨐ

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值