lottery.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <!DOCTYPE html>
  2. <html lang="en" style="width: 100%">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>抽奖</title>
  8. <script src="js/jquery.min.js"></script>
  9. <link rel="stylesheet" href="css/lottery2.css" type="text/css" />
  10. <script type="text/javascript">
  11. //从localstorage中取得ID
  12. var id = localStorage.userId;
  13. var current = 0;
  14. var last = 0;
  15. var threshold = 0;
  16. var speed = 1;
  17. var enable = true;
  18. var src = null;
  19. var recordId = null;
  20. $(function () {
  21. //进入和窗口缩放时重新设置内容位置
  22. setPosition();
  23. $(window).resize(function () {
  24. setPosition();
  25. });
  26. //id设置进入localstorage
  27. localStorage.setItem("userId", id);
  28. //在这里查看是否有id
  29. if(id == null || id == undefined || id == ""){
  30. window.location.href = "http://wx.ttkuaiban.com/minigame";
  31. }
  32. //获取
  33. $.post("./prize/luckDrawList", {}, function(resp) {
  34. if (resp.code == 'error') {
  35. console.log(resp.code);
  36. }else{
  37. for(let index in resp.data){
  38. $(".advertisement").append("<li>恭喜" + resp.data[index].nickName + "获得了" + resp.data[index].prize + "</li>")
  39. }
  40. }
  41. });
  42. //点击查看结果
  43. $(".check_result").click(function(){
  44. window.location.href = "result.html";
  45. })
  46. //点击抽奖
  47. $(".button").click(function () {
  48. if(enable == true){
  49. //获取抽奖结果
  50. $.post("./prize/luckDraw", {userId: id}, function(resp) {
  51. if (resp.code == 'error') {
  52. alert(resp.msg);
  53. }else{
  54. //进入不可点击状态
  55. enable = false;
  56. //设置初始速度
  57. speed = 60;
  58. recordId = resp.data.prizeRecord;
  59. //设置要中奖的位置 1.5没有 0十二瓶 4一升 2.6五百毫升 3书 7肥皂
  60. if(resp.data.prizeLevel == -1){
  61. var rand = Math.round(Math.random()*2);
  62. console.log(rand);
  63. if(rand <= 1){
  64. threshold = 1;
  65. }else{
  66. threshold = 5;
  67. }
  68. }else if(resp.data.prizeLevel == 0){
  69. threshold = 0;
  70. src = "images/reward_oil60_2.png";
  71. }else if(resp.data.prizeLevel == 1){
  72. threshold = 2;
  73. src = "images/reward_oil5_2.png";
  74. }else if(resp.data.prizeLevel == 2){
  75. threshold = 4;
  76. src = "images/reward_oil10_2.png";
  77. }else if(resp.data.prizeLevel == 3){
  78. threshold = 7;
  79. src = "images/reward_soap2.png";
  80. }else if(resp.data.prizeLevel == 4){
  81. threshold = 3;
  82. src = "images/reward_book2.png";
  83. }else{
  84. threshold = 1;
  85. }
  86. //配置移动次数
  87. last = 56 + threshold - current;
  88. setTimeout(function(){next(current)}, 1000);
  89. }
  90. });
  91. }
  92. });
  93. //谢谢惠顾后点击的按钮
  94. $(".result_failed_button").click(function () {
  95. window.location.href = "index.html";
  96. });
  97. //领取奖品按钮
  98. $(".result_success_button").click(function () {
  99. var name = $(".result_success_name").val();
  100. var phone = $(".result_success_phone").val();
  101. if(name == "" || phone == ""){
  102. alert("请填写完整信息");
  103. }else{
  104. $.post("./prize/luckDrawAddInfo", {
  105. id: recordId,
  106. phone: phone,
  107. username: name
  108. }, function(resp) {
  109. if (resp.code == 'error') {
  110. console.log(resp.code);
  111. }else{
  112. alert("填写成功");
  113. window.location.href = "index.html";
  114. }
  115. });
  116. }
  117. });
  118. });
  119. //重新设置内容位置
  120. function setPosition() {
  121. $(".pool").css("top", $(document).width() / 1.9);
  122. $(".container").css("top", $(document).width() / 1.75).css("height", $(document).width() / 1.6);
  123. $(".item").css("height", $(".container").width() / 3.9);
  124. $(".title").css("top", $(".container").width() * 2.35);
  125. $(".check_result").css("top", $(".container").width() * 2.36);
  126. $(".tips").css("top", $(".container").width() * 2.45);
  127. $(".mask").css("height", $(document).height());
  128. $(".result_failed_button").css("top", $(".container").width() * 1.6);
  129. $(".result_success_title").css("top", $(".container").width() * 0.69);
  130. $(".result_success_logo").css("top", $(".container").width() * 0.9);
  131. $(".result_success_name").css("top", $(".container").width() * 1.35);
  132. $(".result_success_phone").css("top", $(".container").width() * 1.59);
  133. $(".result_success_button").css("top", $(".container").width() * 1.82);
  134. $(".case").css("top", $(".container").width() * 1.9);
  135. }
  136. //激活移动
  137. function next() {
  138. $(".item" + current).removeClass("active");
  139. $(".item" + (current + 1) % 8).addClass("active");
  140. current = (current + 1) % 8;
  141. //10以下开始减速
  142. if(last < 10){
  143. speed += 60;
  144. }
  145. //剩余次数8以下并且到了号时
  146. if(!(last-- < 8 && current == threshold)){
  147. setTimeout(function(){next()}, speed);
  148. }else{
  149. setTimeout(function(){
  150. if(threshold == 1 || threshold == 3 || threshold == 5){
  151. failed();
  152. }else{
  153. success();
  154. }
  155. enable = true;
  156. }, 1500);
  157. }
  158. }
  159. //中奖之后
  160. function success(){
  161. $(".mask").show();
  162. $(".success").show();
  163. $(".result_success_title").show();
  164. $(".result_success_logo").show();
  165. $(".result_success_name").show();
  166. $(".result_success_phone").show();
  167. $(".result_success_button").show();
  168. $(".result_success_logo").attr("src", src);
  169. }
  170. //谢谢惠顾
  171. function failed(){
  172. $(".mask").show();
  173. $(".failed").show();
  174. $(".result_failed_button").show();
  175. }
  176. //判断微信分享
  177. document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
  178. //发送给好友
  179. WeixinJSBridge.on('menu:share:appmessage', function(argv){
  180. $.post("./prize/luckDrawAddShare", {uid: id}, function(resp) {
  181. if (resp.code == 'error') {
  182. console.log(resp.code);
  183. }else{
  184. alert("分享成功");
  185. }
  186. });
  187. });
  188. //分享到朋友圈
  189. WeixinJSBridge.on('menu:share:timeline', function(argv){
  190. $.post("./prize/luckDrawAddShare", {uid: id}, function(resp) {
  191. if (resp.code == 'error') {
  192. console.log(resp.code);
  193. }else{
  194. alert("分享成功");
  195. }
  196. });
  197. });
  198. }, false);
  199. </script>
  200. </head>
  201. <body style="width: 100%">
  202. <img class="background" src="images/lottery_background_red.png">
  203. <img class="pool" src="images/lottery_pool.png">
  204. <div class="container">
  205. <img class="item item0" src="images/reward_oil60.png">
  206. <img class="item item1" src="images/reward_null.png">
  207. <img class="item item2" src="images/reward_oil5.png">
  208. <img class="item item7" src="images/reward_soap.png">
  209. <img class="item button" src="images/lottery_button.png">
  210. <img class="item item3" src="images/reward_book.png">
  211. <img class="item item6" src="images/reward_oil5.png">
  212. <img class="item item5" src="images/reward_null.png">
  213. <img class="item item4" src="images/reward_oil10.png">
  214. </div>
  215. <span class="title"><span style="color: #FF356B">活动</span>说明</span>
  216. <span class="tips">1.中奖者留下姓名和电话,在活动结束后会联系邮寄奖品;<br>
  217. 2.微博参与抽奖方式:<br>
  218. 关注@贝蒂斯橄榄油官方微博,转发或评论置顶微博并上传“游戏结果海报”。
  219. </span>
  220. <div class="case">
  221. <div class="part2" id="part2">
  222. <div id="scroll1">
  223. <ul class="advertisement">
  224. </ul>
  225. </div>
  226. <div id="scroll2"></div>
  227. </div>
  228. </div>
  229. <script type="text/javascript">
  230. var PartArea = document.getElementById('part2');
  231. var Scroll1 = document.getElementById('scroll1');
  232. var Scroll2 = document.getElementById('scroll2');
  233. Scroll2.innerHTML = Scroll1.innerHTML;
  234. function roll() {
  235. if(Scroll2.offsetHeight - PartArea.scrollTop <= 0) {
  236. PartArea.scrollTop -= Scroll1.offsetHeight;
  237. } else {
  238. PartArea.scrollTop++;
  239. }
  240. }
  241. var StopRoll = setInterval(roll, 60);
  242. PartArea.onmouseover = function () {
  243. clearInterval(StopRoll);
  244. }
  245. PartArea.onmouseout = function () {
  246. StopRoll = setInterval(roll, 60);
  247. }
  248. </script>
  249. <div class="mask" style="display: none;"></div>
  250. <img class="result success" src="images/result_success.png" style="display: none;">
  251. <p class="result_success_title" style="display: none;">输入个人信息进行领奖</p>
  252. <img class="result_success_logo" style="display: none;">
  253. <input class="result_success_name" type="text" placeholder="姓名" style="display: none;">
  254. <input class="result_success_phone" type="text" placeholder="手机号" style="display: none;">
  255. <img class="result_success_button" src="images/result_success_button.png" style="display: none;">
  256. <img class="result failed" src="images/result_failed.png" style="display: none;">
  257. <img class="result_failed_button" src="images/result_failed_button.png" style="display: none;">
  258. <span class="check_result">我的中奖结果</span>
  259. </body>
  260. </html>