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

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<title>抽奖效果演示</title>
<style>
.rotary { position: relative; width: 854px; height: 504px; margin: 0 auto; background: #d71f2e url(images/bg1.png);}
.rotaryArrow { position: absolute; left: 181px; top: 104px; width: 294px; height: 294px; cursor: pointer; background-image: url(images/arrow.png);}

.list { position: absolute; right: 48px; top: 144px; width: 120px; height: 320px; overflow: hidden;}
.list h3 { display: none;}
.list ul { list-style-type: none;}
.list li { height: 37px; font: 14px/37px "Microsoft Yahei"; color: #ffea76; text-indent: 25px; background: url(images/user.png) 0 no-repeat;}

.result { display: none; position: absolute; left: 130px; top: 190px; width: 395px; height: 118px; background-color: rgba(0,0,0,0.75); filter: alpha(opacity=90);}
.result a { position: absolute; right: 5px; top: 5px; width: 25px; height: 25px; text-indent: -100px; background-image: url(images/close.png); overflow: hidden;}
.result p { padding: 45px 15px 0; font: 16px "Microsoft Yahei"; color: #fff; text-align: center;}
.result em { color: #ffea76; font-style: normal;}
</style>
</head>

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

<!-- Demo start  -->
<div class="rotary">
	<div class="rotaryArrow" id="rotaryArrow"></div>
	<!--<div class="list">
		<h3>中奖名单</h3>
		<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 = [0, 1, 2, 3, 4, 5, 6];
		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({
			angle: 0,
			duration: 5000,
			animateTo: angle + 1440,  //angle是图片上各奖项对应的角度,1440是让指针固定旋转4圈
			callback: function(){
				$resultTxt.html(text);
				$result.show();
			}
		});
	};

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

<!-- 以下是统计及其他信息,与演示无关,不必理会 -->
<style>
* { margin: 0; padding: 0;}
body { font-family: Consolas,arial,"宋体";}
h1 { width: 900px; margin: 40px auto; font: 32px "Microsoft Yahei"; text-align: center;}
.explain, .dowebok-explain { margin-top: 20px; font-size: 14px; text-align: center; color: #f50;}

.vad { margin: 50px 0 5px; font-family: Consolas,arial,宋体; text-align:center;}
.vad a { display: inline-block; height: 36px; line-height: 36px; margin: 0 5px; padding: 0 50px; font-size: 14px; text-align:center; color:#eee; text-decoration: none; background-color: #222;}
.vad a:hover { color: #fff; background-color: #000;}
.thead { width: 728px; height: 90px; margin: 0 auto; border-bottom: 40px solid #fff;}

.code { position: relative; margin-top: 100px; padding-top: 41px;}
.code h3 { position: absolute; top: 0; z-index: 10; width: 100px; height: 40px; font: 16px/40px "Microsoft Yahei"; text-align: center; cursor: pointer;}
.code .cur { border: 1px solid #f0f0f0; border-bottom: 1px solid #f8f8f8; background-color: #f8f8f8;}
.code .h31 { left: 0;}
.code .h32 { left: 102px;}
.code .h33 { left: 204px;}
.code .h34 { left: 306px;}
.code { width: 900px; margin-left: auto; margin-right: auto;}
pre { padding: 15px 0; border: 1px solid #f0f0f0; background-color: #f8f8f8;}
.f-dn { display: none;}
</style>

</body>
</html>
时间: 2024-08-29 14:00:12

在线抽奖大转盘和概率计算的相关文章

javascript+css3实现抽奖大转盘

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Typ

PHP新写的大转盘抽奖源码

中奖概率 抽奖大转盘演示:http://www.sucaihuo.com/php/3301.html function getRand($proArr, $proCount) { $result = ''; $proSum = 0; foreach ($proCount as $key => $val) { if ($val <= 0) { continue; } else { $proSum = $proSum + $proArr[$key]; } } foreach ($proArr as

大转盘抽奖css3+js(简单书写)

今天花了一段时间简单写了下抽奖大转盘,这里写的只是自己想到的简单的写了下(也希望收获其他想法),后续,再写的话会更新. 大体思路:页面加载完成后,通过监听开始按钮的点击事件.然后会根据产生的随机数,通过控制旋转针对象的transform属性,然后进行旋转,最后在结束后获取存储来数组中对应的抽奖内容最后弹出. 知识点:transform, translation,js数组,Math等等 先看下效果,没有素材,只是用css简单的布了下局.不要喷我比较简陋,嘿嘿. 接下来是基本代码结构: 1 <div

js幸运大转盘开发

最终效果实例下载:http://www.oschina.net/code/snippet_2352644_54997 一.大转盘准备工作 网上的一个抽奖大转盘实例http://www.jq22.com/yanshi2252 这就是我们要开发的效果,不过我们是让指针转,我们先分析这个效果: 结构有2部分,上面是指针背景图,下面是奖项图 点击指针元素开始抽奖,会转动一定圈数停下来 停下来的位置指针指使那个奖项,就会弹出获奖信息提示 这是参考效果,我们分析自己的大概实现: 同样上下2部分 点击指针转动

中奖概率算法(php 可用于刮刮卡,大转盘等抽奖算法)

php中奖概率算法,可用于刮刮卡,大转盘等抽奖算法.用法很简单,代码里有详细注释说明,一看就懂 <?php /* * 经典的概率算法, * $proArr是一个预先设置的数组, * 假设数组为:array(100,200,300,400), * 开始是从1,1000 这个概率范围内筛选第一个数是否在他的出现概率范围之内, * 如果不在,则将概率空间,也就是k的值减去刚刚的那个数字的概率空间, * 在本例当中就是减去100,也就是说第二个数是在1,900这个范围内筛选的. * 这样 筛选到最终,总

php中奖概率算法,可用于刮刮卡,大转盘等抽奖算法

php中奖概率算法,可用于刮刮卡,大转盘等抽奖算法.用法很简单,代码里有详细注释说明,一看就懂 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 <!--?

大转盘抽奖

这周做了2个大转盘抽奖,一个使用了jQueryRotate.2.2.js插件,兼容到IE6,另外一个利用css3自己尝试写的 1.插件jQueryRotate.2.2.js(兼容基本浏览器,兼容到IE6) 效果查看: 此插件必须事先引入jquery插件,PC端推荐 JS插件代码: // VERSION: 2.2 LAST UPDATE: 13.03.2012 /* * Licensed under the MIT license: http://www.opensource.org/licens

jQuery幸运大转盘_jQuery+PHP抽奖程序的简单实现

在线实例 查看演示 完整代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv

原型导航应用于大转盘抽奖客户端显示页面实例

<html><head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"> <title>大转盘客户端</title> <meta name="keyw