暂无描述

rotateCircle.js 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. var turnplate = {
  2. restaraunts: [], //大转盘奖品名称
  3. colors: [], //大转盘奖品区块对应背景颜色
  4. outsideRadius: 192, //大转盘外圆的半径
  5. textRadius: 155, //大转盘奖品位置距离圆心的距离
  6. insideRadius: 68, //大转盘内圆的半径
  7. startAngle: 0, //开始角度
  8. coin: 0,//金币数
  9. bRotate: false, //false:停止;ture:旋转
  10. };
  11. var test=null,//定时器
  12. hasSuccess= 0,
  13. progressWidth=20,//进度的百分比
  14. time='',//抽奖次数
  15. // cid='1002',imei='352936095523931',androidId='6c735b635fe943c852e8392152f20ac8',version='1.5.4',secretkey='3d0e4b94e04b8dcca1cedb9c33051173',goldCount='',gameId='',hasHide=false,emptyPosition='';//空位置
  16. cid='',imei='',androidId='',version='',secretkey='3d0e4b94e04b8dcca1cedb9c33051173',goldCount='',gameId='',hasHide=false,emptyPosition='',//空位置
  17. question_id=-1,
  18. alertCoin=0;;
  19. // 旋转到礼包之后,弹出礼包,礼包消失后,弹出广告
  20. // 旋转到金币之后,弹出广告
  21. $(document).ready(function () {
  22. turnplate.restaraunts = ["1", "2", "1", "2", "1", "2", "1", "2"];
  23. turnplate.colors = ["#FFF4D6", "#FFFFFF", "#FFF4D6", "#FFFFFF", "#FFF4D6", "#FFFFFF", "#FFF4D6", "#FFFFFF"];
  24. var angles = (360 / turnplate.restaraunts.length) - (360 / (turnplate.restaraunts.length * 2));
  25. if (angles < 270) {
  26. angles = 270 - angles;
  27. } else {
  28. angles = 360 - angles + 270;
  29. }
  30. $('#wheelcanvas').rotate(angles)
  31. //旋转转盘 item:奖品位置; txt:提示语;
  32. var rotateFn = function (item, txt) {
  33. var angles = item * (360 / turnplate.restaraunts.length) - (360 / (turnplate.restaraunts.length * 2));
  34. if (angles < 270) {
  35. angles = 270 - angles;
  36. } else {
  37. angles = 360 - angles + 270;
  38. }
  39. $('#wheelcanvas').stopRotate();
  40. $('#wheelcanvas').rotate({
  41. angle: 0,
  42. animateTo: angles + 1800,
  43. duration: 5000,
  44. callback: function () {
  45. // 下载链接
  46. if(txt%2==0&&item>=4) {
  47. hasSuccess=0;
  48. question_id=1;
  49. initGold();
  50. $(".mask").show();
  51. $(".toast").show();
  52. setTimeout(function(){
  53. $(".mask").hide();
  54. $(".toast").hide();
  55. window.location.href=lastHref()+"/moveAgainUpload.html"
  56. },400)
  57. // 礼包
  58. }else if(txt%2==0&&item<4) {
  59. hasSuccess=0;
  60. question_id=1;
  61. initGold();
  62. $(".mask").show();
  63. $(".toast").show();
  64. setTimeout(function(){
  65. $(".mask").hide();
  66. $(".toast").hide();
  67. taskObj.h5_adStart();
  68. },400)
  69. }else {
  70. taskObj.game_done(Number(parseQueryString("id")),Number(alertCoin),true,Number(-1));
  71. }
  72. // 2是礼包
  73. // if(txt%2==0) {
  74. // hasSuccess=0;
  75. // question_id=1;
  76. // initGold();
  77. // $(".mask").show();
  78. // $(".toast").show();
  79. // setTimeout(function(){
  80. // $(".mask").hide();
  81. // $(".toast").hide();
  82. // taskObj.h5_adStart();
  83. // },400)
  84. // }else {
  85. // taskObj.game_done(Number(parseQueryString("id")),Number(alertCoin),true,Number(-1));
  86. // }
  87. try {
  88. // 切换底部广告
  89. taskObj.checkAd(350,260);
  90. }catch(e) {
  91. }
  92. turnplate.bRotate = !turnplate.bRotate;
  93. }
  94. });
  95. };
  96. getToken();
  97. adSize();//添加广告位
  98. $('.pointer').click(function () {
  99. if (turnplate.bRotate) return;
  100. turnplate.bRotate = !turnplate.bRotate;
  101. //获取随机数(奖品个数范围内)
  102. var item = rnd(1,turnplate.restaraunts.length);
  103. if(item%2==1) {
  104. question_id=1;
  105. hasSuccess=1
  106. getGold();
  107. }
  108. // var item=2;
  109. //奖品数量等于10,指针落在对应奖品区域的中心角度[252, 216, 180, 144, 108, 72, 36, 360, 324, 288]
  110. rotateFn(item, turnplate.restaraunts[item - 1]);
  111. });
  112. shandeng();
  113. });
  114. // 广告
  115. function adSize(){
  116. taskObj.onLayoutAdSize(845,350,260,14)
  117. }
  118. function shandeng () {
  119. //闪灯效果
  120. var num = 0;
  121. test=setInterval(function(){
  122. num++;
  123. if(num%2==0){
  124. $(".one").hide();
  125. $(".two").show();
  126. }else{
  127. $(".one").show();
  128. $(".two").hide();
  129. }
  130. $(".pointer").addClass("scale");
  131. },500)
  132. }
  133. $("button").on("click",function(){
  134. $(".mask").hide();
  135. $(".rule_content").hide();
  136. $("body").attr("style","overflow:hidden;")
  137. })
  138. function rnd(n, m) {
  139. var random = Math.floor(Math.random() * (m - n + 1) + n);
  140. return random;
  141. }
  142. function showRule() {
  143. $(".mask").show();
  144. $(".rule_content").show();
  145. $(".rule_content").show();
  146. $("body").attr("style","overflow:hidden;")
  147. }
  148. //页面所有元素加载完毕后执行drawRouletteWheel()方法对转盘进行渲染
  149. window.onload = function () {
  150. drawRouletteWheel();
  151. };
  152. function drawRouletteWheel() {
  153. var canvas = document.getElementById("wheelcanvas");
  154. if (canvas.getContext) {
  155. //根据奖品个数计算圆周角度
  156. var arc = Math.PI / (turnplate.restaraunts.length / 2);
  157. var ctx = canvas.getContext("2d");
  158. //在给定矩形内清空一个矩形
  159. ctx.rotate(angle + arc / 2 + Math.PI / 2 + 0.8);
  160. ctx.clearRect(0, 0, 422, 422);
  161. //strokeStyle 属性设置或返回用于笔触的颜色、渐变或模式
  162. ctx.strokeStyle = "transparent";
  163. ctx.font = '16px Microsoft YaHei';
  164. for (var i = 0; i < turnplate.restaraunts.length; i++) {
  165. var angle = turnplate.startAngle + i * arc;
  166. ctx.fillStyle = turnplate.colors[i];
  167. // ctx.fillStyle = 'transparent';
  168. ctx.beginPath();
  169. //arc(x,y,r,起始角,结束角,绘制方向) 方法创建弧/曲线(用于创建圆或部分圆)
  170. ctx.arc(211, 211, turnplate.outsideRadius, angle, angle + arc, false);
  171. ctx.arc(211, 211, turnplate.insideRadius, angle + arc, angle, true);
  172. ctx.stroke();
  173. ctx.fill();
  174. //锁画布(为了保存之前的画布状态)
  175. ctx.save();
  176. //----绘制奖品开始----
  177. ctx.fillStyle = "#E5302F";
  178. //translate方法重新映射画布上的 (0,0) 位置
  179. ctx.translate(211 + Math.cos(angle + arc / 2) * turnplate.textRadius, 211 + Math.sin(angle + arc / 2) * turnplate.textRadius);
  180. //rotate方法旋转当前的绘图
  181. ctx.rotate(angle + arc / 2 + Math.PI / 2);
  182. if(i%2==1) {
  183. var img = document.getElementById("shan-img");
  184. img.onload = function () {
  185. ctx.drawImage(img, -32, -5);
  186. };
  187. ctx.drawImage(img, -32, -5);
  188. }else {
  189. var img = document.getElementById("sorry-img");
  190. img.onload = function () {
  191. ctx.drawImage(img, -32, -5);
  192. };
  193. ctx.drawImage(img, -32, -5);
  194. }
  195. //把当前画布返回(调整)到上一个save()状态之前
  196. ctx.restore();
  197. //----绘制奖品结束----
  198. }
  199. }else {
  200. drawRouletteWheel()
  201. }
  202. }
  203. $(".progress li img").on("click",function(){
  204. getGold(this,$(this).parent().find("span").text(),1);
  205. })
  206. function getToken() {
  207. try {
  208. var data=JSON.parse(taskObj.jsGetToken());
  209. cid=data.cid,imei=data.imei,androidId=data.androidId,version=data.version,token=data.token
  210. // 获取金币
  211. initGold();
  212. }catch(e) {
  213. token = 'e094ced38ef917b5219bd5a4f79c261011855563'
  214. initGold();
  215. }
  216. }
  217. $(".back").on("click",function() {
  218. if(hasSuccess) {
  219. var target=lastHref()+"/taskList.html?id="+parseQueryString("id")
  220. taskObj.h5_back(target)
  221. }else {
  222. var target=lastHref()+"/taskList.html?id=-1"
  223. taskObj.h5_back(target)
  224. }
  225. })
  226. // 金币初始化
  227. function initGold() {
  228. var time1=new Date().getTime();
  229. var arr=["hasSuccess=0","question_id="+question_id,"type="+parseQueryString("id"),"time="+time1]
  230. var sign=arr.join("&")
  231. sign=md5(sign+secretkey)
  232. $.ajax({
  233. type: 'post',
  234. url: '/api/V3/getUserAdvertStatus',
  235. headers:{
  236. token:token,
  237. cid:cid,//渠道号暂时写死
  238. imei:imei,
  239. time:time1,
  240. sign:sign,
  241. androidId:androidId,
  242. },
  243. data: {
  244. type: parseQueryString("id"),
  245. hasSuccess: 0,
  246. question_id:question_id
  247. },
  248. success: function (res) {
  249. var res=JSON.parse(res)
  250. if (res && res.res.success == 1) {
  251. $(".left").text("剩余次数:"+res.res.residualCount)
  252. if(res.res.residualCount==0) {
  253. var msgBox = $('.alert-info');
  254. msgBox.children('p').text("今日游戏次数已用完,明日再来吧");
  255. msgBox.show();
  256. }
  257. time = res.res.totalCount-res.res.residualCount
  258. coin = res.res.coin
  259. question_id = res.res.question_id
  260. var extra = res.res.extra
  261. for(var i in extra) {
  262. switch (extra[i]) {
  263. case 5:
  264. $(".first .static").addClass("move");
  265. break;
  266. case 30:
  267. $(".second .static").addClass("move");
  268. break;
  269. case 60:
  270. $(".third .static").addClass("move");
  271. break;
  272. case 100:
  273. $(".fourth .static").addClass("move");
  274. break;
  275. }
  276. }
  277. if(time>5) {
  278. if(extra.length==0) {
  279. $(".first .static").hide();
  280. $(".first .active").show();
  281. }
  282. for(var i in extra) {
  283. if(extra[i]!=5) {
  284. $(".first .static").hide();
  285. $(".first .active").show();
  286. }else {
  287. $(".first .static").show();
  288. $(".first .active").hide();
  289. }
  290. }
  291. }
  292. if(time>30) {
  293. if(extra.length==0) {
  294. $(".second .static").hide();
  295. $(".second .active").show();
  296. }
  297. for(var i in extra) {
  298. if(extra[i]!=30) {
  299. $(".second .static").hide();
  300. $(".second .active").show();
  301. }else {
  302. $(".second .static").show();
  303. $(".second .active").hide();
  304. }
  305. }
  306. }
  307. if(time>60) {
  308. if(extra.length==0) {
  309. $(".third .static").hide();
  310. $(".third .active").show();
  311. }
  312. for(var i in extra) {
  313. if(extra[i]!=60) {
  314. $(".third .static").hide();
  315. $(".third .active").show();
  316. }else {
  317. $(".third .static").show();
  318. $(".third .active").hide();
  319. }
  320. }
  321. }
  322. if(time>100) {
  323. if(extra.length==0) {
  324. $(".fourth .static").hide();
  325. $(".fourth .active").show();
  326. }
  327. for(var i in extra) {
  328. if(extra[i]!=100) {
  329. $(".fourth .static").hide();
  330. $(".fourth .active").show();
  331. }else {
  332. $(".fourth .static").show();
  333. $(".fourth .active").hide();
  334. }
  335. }
  336. }
  337. var precent='';//抽奖百分比
  338. if(time<5) {
  339. precent=100/5*time;$(".first .line").find(".active_item").width(precent+'%');
  340. }else if(time>=5&&time<30) {
  341. precent=100/25*(time-5);
  342. $(".first .line").find(".active_item").width('100%');
  343. $(".first .last").attr("style","background:#fff");
  344. $(".second .line").find(".active_item").width(precent+'%');
  345. }else if(time>=30&&time<60) {
  346. precent=100/30*(time-30);
  347. $(".first .line").find(".active_item").width('100%');
  348. $(".first .last").attr("style","background:#fff");
  349. $(".second .line").find(".active_item").width('100%');
  350. $(".second .last").attr("style","background:#fff")
  351. $(".third .line").find(".active_item").width(precent+'%');
  352. }else if(time>=60&&time<100) {
  353. precent=100/40*(time-60);
  354. $(".first .line").find(".active_item").width('100%');
  355. $(".first .last").attr("style","background:#fff");
  356. $(".second .line").find(".active_item").width('100%');
  357. $(".second .last").attr("style","background:#fff")
  358. $(".third .line").find(".active_item").width('100%');
  359. $(".third .last").attr("style","background:#fff");
  360. $(".fourth .line").find(".active_item").width(precent+'%');
  361. }else {
  362. $(".first .line").find(".active_item").width('100%');
  363. $(".first .last").attr("style","background:#fff");
  364. $(".second .line").find(".active_item").width('100%');
  365. $(".second .last").attr("style","background:#fff")
  366. $(".third .line").find(".active_item").width('100%');
  367. $(".fourth .line").find(".active_item").width('100%');
  368. $(".fourth .last").attr("style","background:#fff")
  369. }
  370. }else {
  371. showMsg(res.message)
  372. }
  373. },
  374. error: function () {
  375. showMsg('网络错误,请稍后再试!')
  376. }
  377. })
  378. }
  379. // 领取金币
  380. function getGold(type,id,other) {
  381. hasSuccess=1
  382. var time1=new Date().getTime();
  383. var arr=["question_id="+(id?id:'-1'),"type="+parseQueryString("id"),"time="+time1]
  384. var sign=arr.join("&")
  385. sign=md5(sign+secretkey)
  386. $.ajax({
  387. type: 'post',
  388. url: '/api/V3/getAdvertCoin',
  389. headers:{
  390. token:token,
  391. cid:cid,//渠道号暂时写死
  392. imei:imei,
  393. time:time1,
  394. sign:sign,
  395. androidId:androidId,
  396. version:version,
  397. },
  398. data:{
  399. type: parseQueryString("id"),
  400. // hasSuccess: hasSuccess,
  401. question_id: id?id:'-1'
  402. },
  403. success:function (res) {
  404. var res=JSON.parse(res)
  405. if (res && res.code==0) {
  406. $(".left").text("剩余次数:"+res.res.residualCount)
  407. alertCoin=res.res.coin;
  408. var time = res.res.totalCount-res.res.residualCount
  409. var extra = res.res.extra
  410. for(var i in extra) {
  411. switch (extra[i]) {
  412. case 5:
  413. $(".first .static").addClass("move");
  414. break;
  415. case 30:
  416. $(".second .static").addClass("move");
  417. break;
  418. case 60:
  419. $(".third .static").addClass("move");
  420. break;
  421. case 100:
  422. $(".fourth .static").addClass("move");
  423. break;
  424. }
  425. }
  426. if(time>5) {
  427. if(extra.length==0) {
  428. $(".first .static").hide();
  429. $(".first .active").show();
  430. }
  431. for(var i in extra) {
  432. if(extra[i]!=5) {
  433. $(".first .static").hide();
  434. $(".first .active").show();
  435. }else {
  436. $(".first .static").show();
  437. $(".first .active").hide();
  438. }
  439. }
  440. }
  441. if(time>30) {
  442. if(extra.length==0) {
  443. $(".second .static").hide();
  444. $(".second .active").show();
  445. }
  446. for(var i in extra) {
  447. if(extra[i]!=30) {
  448. $(".second .static").hide();
  449. $(".second .active").show();
  450. }else {
  451. $(".second .static").show();
  452. $(".second .active").hide();
  453. }
  454. }
  455. }
  456. if(time>60) {
  457. if(extra.length==0) {
  458. $(".third .static").hide();
  459. $(".third .active").show();
  460. }
  461. for(var i in extra) {
  462. if(extra[i]!=60) {
  463. $(".third .static").hide();
  464. $(".third .active").show();
  465. }else {
  466. $(".third .static").show();
  467. $(".third .active").hide();
  468. }
  469. }
  470. }
  471. if(time>100) {
  472. if(extra.length==0) {
  473. $(".fourth .static").hide();
  474. $(".fourth .active").show();
  475. }
  476. for(var i in extra) {
  477. if(extra[i]!=100) {
  478. $(".fourth .static").hide();
  479. $(".fourth .active").show();
  480. }else {
  481. $(".fourth .static").show();
  482. $(".fourth .active").hide();
  483. }
  484. }
  485. }
  486. if(time<5) {
  487. precent=100/5*time;$(".first .line").find(".active_item").width(precent+'%');
  488. }else if(time>=5&&time<30) {
  489. precent=100/25*(time-5);
  490. $(".first .line").find(".active_item").width('100%');
  491. $(".first .last").attr("style","background:#fff");
  492. $(".second .line").find(".active_item").width(precent+'%');
  493. }else if(time>=30&&time<60) {
  494. precent=100/30*(time-30);
  495. $(".first .line").find(".active_item").width('100%');
  496. $(".first .last").attr("style","background:#fff");
  497. $(".second .line").find(".active_item").width('100%');
  498. $(".second .last").attr("style","background:#fff")
  499. $(".third .line").find(".active_item").width(precent+'%');
  500. }else if(time>=60&&time<100) {
  501. precent=100/40*(time-60);
  502. $(".first .line").find(".active_item").width('100%');
  503. $(".first .last").attr("style","background:#fff");
  504. $(".second .line").find(".active_item").width('100%');
  505. $(".second .last").attr("style","background:#fff")
  506. $(".third .line").find(".active_item").width('100%');
  507. $(".third .last").attr("style","background:#fff");
  508. $(".fourth .line").find(".active_item").width(precent+'%');
  509. }else {
  510. $(".first .line").find(".active_item").width('100%');
  511. $(".first .last").attr("style","background:#fff");
  512. $(".second .line").find(".active_item").width('100%');
  513. $(".second .last").attr("style","background:#fff")
  514. $(".third .line").find(".active_item").width('100%');
  515. $(".fourth .line").find(".active_item").width('100%');
  516. $(".fourth .last").attr("style","background:#fff")
  517. }
  518. if(type) {
  519. $(type).hide();
  520. $(type).parent().find(".active").show();
  521. }
  522. if(hasSuccess!=1) {
  523. initGold()
  524. }
  525. if(other===1) {
  526. taskObj.game_done(Number(parseQueryString("id")),Number(alertCoin),true,Number(-1));
  527. }
  528. }else {
  529. showMsg(res.res.msg)
  530. }
  531. },
  532. error: function () {
  533. showMsg('网络错误,请稍后再试!')
  534. }
  535. })
  536. }
  537. function parseQueryString(variable) {
  538. var query = window.location.search.substring(1);
  539. var vars = query.split("&");
  540. for (var i=0;i<vars.length;i++) {
  541. var pair = vars[i].split("=");
  542. if(pair[0] == variable){return pair[1];}
  543. }
  544. return(false);
  545. }
  546. function lastHref() {
  547. var test=window.location.pathname;
  548. var newTest=test.split("/")
  549. var test1=newTest[newTest.length-1];
  550. return window.location.origin+test.replace("/"+test1,"")
  551. }