var turnplate = { restaraunts: [], //大转盘奖品名称 colors: [], //大转盘奖品区块对应背景颜色 outsideRadius: 192, //大转盘外圆的半径 textRadius: 155, //大转盘奖品位置距离圆心的距离 insideRadius: 68, //大转盘内圆的半径 startAngle: 0, //开始角度 coin: 0,//金币数 bRotate: false, //false:停止;ture:旋转 }; var test=null,//定时器 hasSuccess= 0, progressWidth=20,//进度的百分比 time='',//抽奖次数 // cid='1002',imei='352936095523931',androidId='6c735b635fe943c852e8392152f20ac8',version='1.5.4',secretkey='3d0e4b94e04b8dcca1cedb9c33051173',goldCount='',gameId='',hasHide=false,emptyPosition='';//空位置 cid='',imei='',androidId='',version='',secretkey='3d0e4b94e04b8dcca1cedb9c33051173',goldCount='',gameId='',hasHide=false,emptyPosition='',//空位置 question_id=-1, alertCoin=0;; // 旋转到礼包之后,弹出礼包,礼包消失后,弹出广告 // 旋转到金币之后,弹出广告 $(document).ready(function () { turnplate.restaraunts = ["1", "2", "1", "2", "1", "2", "1", "2"]; turnplate.colors = ["#FFF4D6", "#FFFFFF", "#FFF4D6", "#FFFFFF", "#FFF4D6", "#FFFFFF", "#FFF4D6", "#FFFFFF"]; var angles = (360 / turnplate.restaraunts.length) - (360 / (turnplate.restaraunts.length * 2)); if (angles < 270) { angles = 270 - angles; } else { angles = 360 - angles + 270; } $('#wheelcanvas').rotate(angles) //旋转转盘 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; } $('#wheelcanvas').stopRotate(); $('#wheelcanvas').rotate({ angle: 0, animateTo: angles + 1800, duration: 5000, callback: function () { // 下载链接 if(txt%2==0&&item>=4) { hasSuccess=0; question_id=1; initGold(); $(".mask").show(); $(".toast").show(); setTimeout(function(){ $(".mask").hide(); $(".toast").hide(); window.location.href=lastHref()+"/moveAgainUpload.html" },400) // 礼包 }else if(txt%2==0&&item<4) { hasSuccess=0; question_id=1; initGold(); $(".mask").show(); $(".toast").show(); setTimeout(function(){ $(".mask").hide(); $(".toast").hide(); taskObj.h5_adStart(); },400) }else { taskObj.game_done(Number(parseQueryString("id")),Number(alertCoin),true,Number(-1)); } // 2是礼包 // if(txt%2==0) { // hasSuccess=0; // question_id=1; // initGold(); // $(".mask").show(); // $(".toast").show(); // setTimeout(function(){ // $(".mask").hide(); // $(".toast").hide(); // taskObj.h5_adStart(); // },400) // }else { // taskObj.game_done(Number(parseQueryString("id")),Number(alertCoin),true,Number(-1)); // } try { // 切换底部广告 taskObj.checkAd(350,260); }catch(e) { } turnplate.bRotate = !turnplate.bRotate; } }); }; getToken(); adSize();//添加广告位 $('.pointer').click(function () { if (turnplate.bRotate) return; turnplate.bRotate = !turnplate.bRotate; //获取随机数(奖品个数范围内) var item = rnd(1,turnplate.restaraunts.length); if(item%2==1) { question_id=1; hasSuccess=1 getGold(); } // var item=2; //奖品数量等于10,指针落在对应奖品区域的中心角度[252, 216, 180, 144, 108, 72, 36, 360, 324, 288] rotateFn(item, turnplate.restaraunts[item - 1]); }); shandeng(); }); // 广告 function adSize(){ taskObj.onLayoutAdSize(845,350,260,14) } function shandeng () { //闪灯效果 var num = 0; test=setInterval(function(){ num++; if(num%2==0){ $(".one").hide(); $(".two").show(); }else{ $(".one").show(); $(".two").hide(); } $(".pointer").addClass("scale"); },500) } $("button").on("click",function(){ $(".mask").hide(); $(".rule_content").hide(); $("body").attr("style","overflow:hidden;") }) function rnd(n, m) { var random = Math.floor(Math.random() * (m - n + 1) + n); return random; } function showRule() { $(".mask").show(); $(".rule_content").show(); $(".rule_content").show(); $("body").attr("style","overflow:hidden;") } //页面所有元素加载完毕后执行drawRouletteWheel()方法对转盘进行渲染 window.onload = function () { drawRouletteWheel(); }; function drawRouletteWheel() { var canvas = document.getElementById("wheelcanvas"); if (canvas.getContext) { //根据奖品个数计算圆周角度 var arc = Math.PI / (turnplate.restaraunts.length / 2); var ctx = canvas.getContext("2d"); //在给定矩形内清空一个矩形 ctx.rotate(angle + arc / 2 + Math.PI / 2 + 0.8); ctx.clearRect(0, 0, 422, 422); //strokeStyle 属性设置或返回用于笔触的颜色、渐变或模式 ctx.strokeStyle = "transparent"; ctx.font = '16px Microsoft YaHei'; for (var i = 0; i < turnplate.restaraunts.length; i++) { var angle = turnplate.startAngle + i * arc; ctx.fillStyle = turnplate.colors[i]; // ctx.fillStyle = 'transparent'; ctx.beginPath(); //arc(x,y,r,起始角,结束角,绘制方向) 方法创建弧/曲线(用于创建圆或部分圆) ctx.arc(211, 211, turnplate.outsideRadius, angle, angle + arc, false); ctx.arc(211, 211, turnplate.insideRadius, angle + arc, angle, true); ctx.stroke(); ctx.fill(); //锁画布(为了保存之前的画布状态) ctx.save(); //----绘制奖品开始---- ctx.fillStyle = "#E5302F"; //translate方法重新映射画布上的 (0,0) 位置 ctx.translate(211 + Math.cos(angle + arc / 2) * turnplate.textRadius, 211 + Math.sin(angle + arc / 2) * turnplate.textRadius); //rotate方法旋转当前的绘图 ctx.rotate(angle + arc / 2 + Math.PI / 2); if(i%2==1) { var img = document.getElementById("shan-img"); img.onload = function () { ctx.drawImage(img, -32, -5); }; ctx.drawImage(img, -32, -5); }else { var img = document.getElementById("sorry-img"); img.onload = function () { ctx.drawImage(img, -32, -5); }; ctx.drawImage(img, -32, -5); } //把当前画布返回(调整)到上一个save()状态之前 ctx.restore(); //----绘制奖品结束---- } }else { drawRouletteWheel() } } $(".progress li img").on("click",function(){ getGold(this,$(this).parent().find("span").text(),1); }) function getToken() { try { var data=JSON.parse(taskObj.jsGetToken()); cid=data.cid,imei=data.imei,androidId=data.androidId,version=data.version,token=data.token // 获取金币 initGold(); }catch(e) { token = 'e094ced38ef917b5219bd5a4f79c261011855563' initGold(); } } $(".back").on("click",function() { if(hasSuccess) { var target=lastHref()+"/taskList.html?id="+parseQueryString("id") taskObj.h5_back(target) }else { var target=lastHref()+"/taskList.html?id=-1" taskObj.h5_back(target) } }) // 金币初始化 function initGold() { var time1=new Date().getTime(); var arr=["hasSuccess=0","question_id="+question_id,"type="+parseQueryString("id"),"time="+time1] var sign=arr.join("&") sign=md5(sign+secretkey) $.ajax({ type: 'post', url: '/api/V3/getUserAdvertStatus', headers:{ token:token, cid:cid,//渠道号暂时写死 imei:imei, time:time1, sign:sign, androidId:androidId, }, data: { type: parseQueryString("id"), hasSuccess: 0, question_id:question_id }, success: function (res) { var res=JSON.parse(res) if (res && res.res.success == 1) { $(".left").text("剩余次数:"+res.res.residualCount) if(res.res.residualCount==0) { var msgBox = $('.alert-info'); msgBox.children('p').text("今日游戏次数已用完,明日再来吧"); msgBox.show(); } time = res.res.totalCount-res.res.residualCount coin = res.res.coin question_id = res.res.question_id var extra = res.res.extra for(var i in extra) { switch (extra[i]) { case 5: $(".first .static").addClass("move"); break; case 30: $(".second .static").addClass("move"); break; case 60: $(".third .static").addClass("move"); break; case 100: $(".fourth .static").addClass("move"); break; } } if(time>5) { if(extra.length==0) { $(".first .static").hide(); $(".first .active").show(); } for(var i in extra) { if(extra[i]!=5) { $(".first .static").hide(); $(".first .active").show(); }else { $(".first .static").show(); $(".first .active").hide(); } } } if(time>30) { if(extra.length==0) { $(".second .static").hide(); $(".second .active").show(); } for(var i in extra) { if(extra[i]!=30) { $(".second .static").hide(); $(".second .active").show(); }else { $(".second .static").show(); $(".second .active").hide(); } } } if(time>60) { if(extra.length==0) { $(".third .static").hide(); $(".third .active").show(); } for(var i in extra) { if(extra[i]!=60) { $(".third .static").hide(); $(".third .active").show(); }else { $(".third .static").show(); $(".third .active").hide(); } } } if(time>100) { if(extra.length==0) { $(".fourth .static").hide(); $(".fourth .active").show(); } for(var i in extra) { if(extra[i]!=100) { $(".fourth .static").hide(); $(".fourth .active").show(); }else { $(".fourth .static").show(); $(".fourth .active").hide(); } } } var precent='';//抽奖百分比 if(time<5) { precent=100/5*time;$(".first .line").find(".active_item").width(precent+'%'); }else if(time>=5&&time<30) { precent=100/25*(time-5); $(".first .line").find(".active_item").width('100%'); $(".first .last").attr("style","background:#fff"); $(".second .line").find(".active_item").width(precent+'%'); }else if(time>=30&&time<60) { precent=100/30*(time-30); $(".first .line").find(".active_item").width('100%'); $(".first .last").attr("style","background:#fff"); $(".second .line").find(".active_item").width('100%'); $(".second .last").attr("style","background:#fff") $(".third .line").find(".active_item").width(precent+'%'); }else if(time>=60&&time<100) { precent=100/40*(time-60); $(".first .line").find(".active_item").width('100%'); $(".first .last").attr("style","background:#fff"); $(".second .line").find(".active_item").width('100%'); $(".second .last").attr("style","background:#fff") $(".third .line").find(".active_item").width('100%'); $(".third .last").attr("style","background:#fff"); $(".fourth .line").find(".active_item").width(precent+'%'); }else { $(".first .line").find(".active_item").width('100%'); $(".first .last").attr("style","background:#fff"); $(".second .line").find(".active_item").width('100%'); $(".second .last").attr("style","background:#fff") $(".third .line").find(".active_item").width('100%'); $(".fourth .line").find(".active_item").width('100%'); $(".fourth .last").attr("style","background:#fff") } }else { showMsg(res.message) } }, error: function () { showMsg('网络错误,请稍后再试!') } }) } // 领取金币 function getGold(type,id,other) { hasSuccess=1 var time1=new Date().getTime(); var arr=["question_id="+(id?id:'-1'),"type="+parseQueryString("id"),"time="+time1] var sign=arr.join("&") sign=md5(sign+secretkey) $.ajax({ type: 'post', url: '/api/V3/getAdvertCoin', headers:{ token:token, cid:cid,//渠道号暂时写死 imei:imei, time:time1, sign:sign, androidId:androidId, version:version, }, data:{ type: parseQueryString("id"), // hasSuccess: hasSuccess, question_id: id?id:'-1' }, success:function (res) { var res=JSON.parse(res) if (res && res.code==0) { $(".left").text("剩余次数:"+res.res.residualCount) alertCoin=res.res.coin; var time = res.res.totalCount-res.res.residualCount var extra = res.res.extra for(var i in extra) { switch (extra[i]) { case 5: $(".first .static").addClass("move"); break; case 30: $(".second .static").addClass("move"); break; case 60: $(".third .static").addClass("move"); break; case 100: $(".fourth .static").addClass("move"); break; } } if(time>5) { if(extra.length==0) { $(".first .static").hide(); $(".first .active").show(); } for(var i in extra) { if(extra[i]!=5) { $(".first .static").hide(); $(".first .active").show(); }else { $(".first .static").show(); $(".first .active").hide(); } } } if(time>30) { if(extra.length==0) { $(".second .static").hide(); $(".second .active").show(); } for(var i in extra) { if(extra[i]!=30) { $(".second .static").hide(); $(".second .active").show(); }else { $(".second .static").show(); $(".second .active").hide(); } } } if(time>60) { if(extra.length==0) { $(".third .static").hide(); $(".third .active").show(); } for(var i in extra) { if(extra[i]!=60) { $(".third .static").hide(); $(".third .active").show(); }else { $(".third .static").show(); $(".third .active").hide(); } } } if(time>100) { if(extra.length==0) { $(".fourth .static").hide(); $(".fourth .active").show(); } for(var i in extra) { if(extra[i]!=100) { $(".fourth .static").hide(); $(".fourth .active").show(); }else { $(".fourth .static").show(); $(".fourth .active").hide(); } } } if(time<5) { precent=100/5*time;$(".first .line").find(".active_item").width(precent+'%'); }else if(time>=5&&time<30) { precent=100/25*(time-5); $(".first .line").find(".active_item").width('100%'); $(".first .last").attr("style","background:#fff"); $(".second .line").find(".active_item").width(precent+'%'); }else if(time>=30&&time<60) { precent=100/30*(time-30); $(".first .line").find(".active_item").width('100%'); $(".first .last").attr("style","background:#fff"); $(".second .line").find(".active_item").width('100%'); $(".second .last").attr("style","background:#fff") $(".third .line").find(".active_item").width(precent+'%'); }else if(time>=60&&time<100) { precent=100/40*(time-60); $(".first .line").find(".active_item").width('100%'); $(".first .last").attr("style","background:#fff"); $(".second .line").find(".active_item").width('100%'); $(".second .last").attr("style","background:#fff") $(".third .line").find(".active_item").width('100%'); $(".third .last").attr("style","background:#fff"); $(".fourth .line").find(".active_item").width(precent+'%'); }else { $(".first .line").find(".active_item").width('100%'); $(".first .last").attr("style","background:#fff"); $(".second .line").find(".active_item").width('100%'); $(".second .last").attr("style","background:#fff") $(".third .line").find(".active_item").width('100%'); $(".fourth .line").find(".active_item").width('100%'); $(".fourth .last").attr("style","background:#fff") } if(type) { $(type).hide(); $(type).parent().find(".active").show(); } if(hasSuccess!=1) { initGold() } if(other===1) { taskObj.game_done(Number(parseQueryString("id")),Number(alertCoin),true,Number(-1)); } }else { showMsg(res.res.msg) } }, error: function () { showMsg('网络错误,请稍后再试!') } }) } function parseQueryString(variable) { var query = window.location.search.substring(1); var vars = query.split("&"); for (var i=0;i