温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

在线抽奖大转盘和概率计算

发布时间:2020-07-06 20:48:35 阅读:1738 作者:飞扬php 栏目:开发技术
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<title>抽奖效果演示</title>
<style>
.rotary { position: relative; width854pxheight504pxmargin0 auto; background#d71f2e url(p_w_picpaths/bg1.png);}
.rotaryArrow { position: absolute; left181pxtop104pxwidth294pxheight294pxcursor: pointer; background-p_w_picpath: url(p_w_picpaths/arrow.png);}

.list { position: absolute; right48pxtop144pxwidth120pxheight320pxoverflow: hidden;}
.list h4 { display: none;}
.list ul { list-style-type: none;}
.list li { height37pxfont14px/37px "Microsoft Yahei"color#ffea76text-indent25pxbackgroundurl(p_w_picpaths/user.png0 no-repeat;}

.result { display: none; position: absolute; left130pxtop190pxwidth395pxheight118pxbackground-colorrgba(0,0,0,0.75); filteralpha(opacity=90);}
.result a { position: absolute; right5pxtop5pxwidth25pxheight25pxtext-indent: -100pxbackground-p_w_picpath: url(p_w_picpaths/close.png); overflow: hidden;}
.result p { padding45px 15px 0font16px "Microsoft Yahei"color#ffftext-align: center;}
.result em { color#ffea76font-style: normal;}
</style>
</head>

<body>
<h2>抽奖效果演示</h2>

<!-- Demo start  -->
<div class="rotary">
	<div class="rotaryArrow" id="rotaryArrow"></div>
	<!--<div class="list">
		<h4>中奖名单</h4>
		<ul>
			<li>jq22.com</li>
			<li>1569****851</li>
			<li>1515****206</li>
			<li>1550****789</li>
			<li>1370****627</li>
			<li>1828****215</li>
			<li>1589****572</li>
			<li>1583****825</li>
			<li>1396****805</li>
			<li>1332****261</li>
			<li>1884****863</li>
			<li>1384****955</li>
			<li>1897****137</li>
			<li>1342****973</li>
			<li>1558****071</li>
			<li>1554****168</li>
			<li>1562****018</li>
			<li>1805****856</li>
			<li>1354****809</li>
			<li>1383****364</li>
		</ul>
	</div>-->
	<div class="result" id="result">
		<p id="resultTxt"></p>
		<a href="javascript:" id="resultBtn" title="关闭">关闭</a>
	</div>
</div>
<!-- Demo end -->

<script src="js/jquery-1.8.3.min.js"></script>
<script src="js/jquery.rotate.min.js"></script>
<script>
$(function(){
	var $rotaryArrow = $('#rotaryArrow');
	var $result = $('#result');
	var $resultTxt = $('#resultTxt');
	var $resultBtn = $('#result');

	$rotaryArrow.click(function(){
		var lottery_flag = 0;
		/**
		 * 数组 lottery为中奖概率数组
		 *
		 * 中奖概率:
		 * 0-不中奖:20%
		 * 1-1元代金券:35%
		 * 2-5元代金券:20%
		 * 3-10元代金券:12%
		 * 4-20元代金券:8%
		 * 5-50元代金券:1%
		 * 6-30元代金券:4%
		 */
		var lottery = [5,3,5,8,12,100,25];
		var data = [0123456];
		for (i=0;i<data.length;i++){
			if (Math.floor(Math.random()*lottery[i]) == 1){
               lottery_flag = data[i];
				break;
			}
		}
		var flag = 177;     //设置未中奖的默认角度
		var date = new Date();
		var seconds = date.getSeconds();
		if(seconds % 2 == 0){
			//根据时间秒数是否被2整除,模拟未中奖时指针对两个未中奖角度的随机
            flag = 0;
		}
		switch(lottery_flag){
			case 1:
				rotateFunc(1,87,'恭喜您获得了 <em>1</em> 元代金券');
				break;
			case 2:
				rotateFunc(2,43,'恭喜您获得了 <em>5</em> 元代金券');
				break;
			case 3:
				rotateFunc(3,134,'恭喜您获得了 <em>10</em> 元代金券');
				break;
			case 4:
				rotateFunc(5,223,'恭喜您获得了 <em>20</em> 元代金券');
				break;
			case 5:
				rotateFunc(6,268,'恭喜您获得了 <em>50</em> 元代金券');
				break;
			case 6:
				rotateFunc(7,316,'恭喜您获得了 <em>30</em> 元代金券');
				break;
			default:
				rotateFunc(0,flag,'很遗憾,这次您未抽中奖,继续加油吧');
		}
	});

	var rotateFunc = function(awards,angle,text){  //awards:奖项,angle:奖项对应的角度
		$rotaryArrow.stopRotate();
		$rotaryArrow.rotate({
			angle0,
			duration5000,
			animateTo: angle + 1440,  //angle是图片上各奖项对应的角度,1440是让指针固定旋转4圈
			callbackfunction(){
				$resultTxt.html(text);
				$result.show();
			}
		});
	};

	$resultBtn.click(function(){
		$result.hide();
	});
});
</script>










<!-- 以下是统计及其他信息,与演示无关,不必理会 -->
<style>
* { margin0padding0;}
body { font-family: Consolas,arial,"宋体";}
h2 { width900pxmargin40px auto; font32px "Microsoft Yahei"text-align: center;}
.explain.dowebok-explain { margin-top20pxfont-size14pxtext-align: center; color#f50;}

.vad { margin50px 0 5pxfont-family: Consolas,arial,宋体; text-align:center;}
.vad a { display: inline-block; height36pxline-height36pxmargin0 5pxpadding0 50pxfont-size14pxtext-align:center; color:#eeetext-decoration: none; background-color#222;}
.vad a:hover { color#fffbackground-color#000;}
.thead { width728pxheight90pxmargin0 auto; border-bottom40px solid #fff;}

.code { position: relative; margin-top100pxpadding-top41px;}
.code h4 { position: absolute; top0z-index10width100pxheight40pxfont16px/40px "Microsoft Yahei"text-align: center; cursor: pointer;}
.code .cur { border1px solid #f0f0f0border-bottom1px solid #f8f8f8background-color#f8f8f8;}
.code .h41 { left0;}
.code .h42 { left102px;}
.code .h43 { left204px;}
.code .h44 { left306px;}
.code { width900pxmargin-left: auto; margin-right: auto;}
pre { padding15px 0border1px solid #f0f0f0background-color#f8f8f8;}
.f-dn { display: none;}
</style>

</body>
</html>
附件:http://down.51cto.com/data/2368005

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI

开发者交流群×