利用jQuery实现移动端转盘抽奖代码



16 60 21



特效描述:利用jQuery实现 移动端 转盘抽奖代码,利用jQuery实现移动端转盘抽奖代码

代码结构

1. 引入CSS

<link rel="stylesheet" href="css/swiper.min.css" />
<link rel="stylesheet" href="css/zzsc.css" />

2. 引入JS

<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.rotate.min.js" ></script>
<script type="text/javascript" src="js/swiper-3.4.2.jquery.min.js" ></script>

3. HTML代码

<div class="box">
	<p class="tit">大转盘抽奖-指定奖品</p>
	<p class="tit">只需要更换turnplate的id就可以更换相应的奖品</p>
	<img class="turntable_zj" src="img/turntable_zj.png" />			
	<img class="pointer" src="img/point.png" />
	<!--转盘文字及图片-->
	<div class="turntable_box">				
		<img class="turntable_bg" src="img/inner.png">
		<div class="item">
			<div id='1'>iphone x</div>
			<img src="img/iphonex.png" />
		</div>
		<div class="item" style="transform: rotate(45deg);">
			<div id='2'>100话费红包</div>
			<img src="img/iphonex.png" />
		</div>
		<div class="item" style="transform: rotate(90deg);">
			<div id='3'>周大福吊坠</div>
			<img src="img/iphonex.png" />
		</div>
		<div class="item" style="transform: rotate(135deg);">
			<div id='4'>50个赠币</div>
			<img src="img/iphonex.png" />
		</div>
		<div class="item" style="transform: rotate(180deg);">
			<div id='5'>爱奇艺月卡</div>
			<img src="img/iphonex.png" />
		</div>
		<div class="item" style="transform: rotate(-135deg);">
			<div id='6'>1个赠币</div>
			<img src="img/iphonex.png" />
		</div>
		<div class="item" style="transform: rotate(-90deg);">
			<div id='7'>欧乐B牙刷</div>
			<img src="img/iphonex.png" />
		</div>
		<div class="item" style="transform: rotate(-45deg);">
			<div id='8'>1个积分</div>
			<img src="img/iphonex.png" />
		</div>
	</div>
	<!--中奖名单轮播-->
	<div class="swiper-container list">
		<div class="swiper-wrapper">
			<div class="swiper-slide">恭喜156****2323抽中iphonex!</div>
			<div class="swiper-slide">恭喜156****2323抽中iphonex!</div>
			<div class="swiper-slide">恭喜156****2323抽中iphonex!</div>
			<div class="swiper-slide">恭喜156****2323抽中iphonex!</div>
			<div class="swiper-slide">恭喜156****2323抽中iphonex!</div>
		</div>
	</div>
	<div class="transDiv"></div>			
</div>
<script>
//只需要更换turnplate的id就可以更换相应的奖品
var turnplate={
	restaraunts:["iphone x", "100话费红包", "周大福吊坠", "50个赠币", "爱奇艺月卡", "1个赠币", "欧乐B牙刷", "1个积分"],       //大转盘奖品名称
	rotateFlag:false,      //false:停止;ture:旋转
	id:1     //抽中的id 1:iphone x  2:100话费红包   3:周大福吊坠 ......
};
$(document).ready(function(){
	//旋转转盘 item:奖品位置; txt:提示语;
	var rotateFn = function (item, txt){
		var angles = item * (360 / turnplate.restaraunts.length) - (360 / (turnplate.restaraunts.length*2));
		if(angles<270){
		 angles = 270 - angles; 
		}else{
		  angles = 360 - angles + 270;
		}
		$('.turntable_box').stopRotate();
		$('.turntable_box').rotate({
			angle:0,
			animateTo:angles+1800+22.5,
			duration:8000,
			callback:function (){
				alert(txt);
				turnplate.rotateFlag = !turnplate.rotateFlag;
			}
		});
	};
	$('.pointer').click(function (){
		if(turnplate.rotateFlag)return;
		turnplate.rotateFlag = !turnplate.rotateFlag;
		var item = turnplate.id;
		//指针落在对应奖品区域的中心角度
		rotateFn(item-2, turnplate.restaraunts[item-1]);
		//console.log(item);
	});	
	var swiper = new Swiper('.list', {
		direction: 'vertical',
		autoplay: true,
		speed:1300,
		loop:true
	});
});  
</script>



用户评论
大牛,别默默的看了,快登录帮我点评一下吧!:)      登录 | 注册


热门标签: 弹出层拖动 窗口 弹出 弹窗 弹出层 提示框 对话框 遮罩 遮罩层 弹窗插件 滑动星星打分 其他 提示框/弹出层 抽奖 转盘抽奖

×
×

注册

官方QQ群

扫描上面二维码加微信群

官方QQ群

jQuery/js讨论群
群号:642649996
Css3+Html5讨论群
群号:322131262

加群请备注:从官网了解到