lottery

功能描述

网页转盘抽奖插件特效代码

依赖的模块

jquery swiper

使用方法

  1. <!--结果弹窗结束-->
  2. <script>
  3. var luck = {
  4. index: 0, //当前转动到哪个位置,起点位置
  5. count: 0, //总共有多少个位置
  6. timer: 0, //setTimeout的ID,用clearTimeout清除
  7. speed: 20, //初始转动速度
  8. times: 0, //转动次数
  9. cycle: 50, //转动基本次数:即至少需要转动多少次再进入抽奖环节
  10. prize: -1, //中奖位置
  11. init: function(id) {
  12. if($("#" + id).find(".luck-unit").length > 0) {
  13. $luck = $("#" + id);
  14. $units = $luck.find(".luck-unit");
  15. this.obj = $luck;
  16. this.count = $units.length;
  17. $luck.find(".luck-unit-" + this.index).addClass("active");
  18. };
  19. },
  20. roll: function() {
  21. var index = this.index;
  22. var count = this.count;
  23. var luck = this.obj;
  24. $(luck).find(".luck-unit-" + index).removeClass("active");
  25. index += 1;
  26. if(index > count - 1) {
  27. index = 0;
  28. };
  29. $(luck).find(".luck-unit-" + index).addClass("active");
  30. this.index = index;
  31. return false;
  32. },
  33. stop: function(index) {
  34. this.prize = index;
  35. return false;
  36. }
  37. };
  38. function roll() {
  39. luck.times += 1;
  40. luck.roll();
  41. if(luck.times > luck.cycle + 10 && luck.prize == luck.index) {
  42. clearTimeout(luck.timer);
  43. luck.prize = -1;
  44. luck.times = 0;
  45. click = false;
  46. } else {
  47. if(luck.times < luck.cycle) {
  48. luck.speed -= 10;
  49. } else if(luck.times == luck.cycle) {
  50. var index = Math.random() * (luck.count) | 0;
  51. if(index > 5) {
  52. index = 7;
  53. } else {
  54. index = 5;
  55. }
  56. luck.prize = index; //最终中奖位置
  57. } else {
  58. if(luck.times > luck.cycle + 10 && ((luck.prize == 0 && luck.index == 7) || luck.prize == luck.index + 1)) {
  59. luck.speed += 110;
  60. } else {
  61. luck.speed += 20;
  62. }
  63. }
  64. if(luck.speed < 40) {
  65. luck.speed = 40;
  66. };
  67. luck.timer = setTimeout(roll, luck.speed);
  68. }
  69. return false;
  70. }
  71. var click = false;
  72. window.onload = function() {
  73. luck.init('luck');
  74. $("#btn").click(function() {
  75. setTimeout(function() {
  76. $(".cover").removeClass("dis_no");
  77. $(".cover_box").removeClass("dis_no");
  78. $("body,html").css({
  79. "height": "100%",
  80. "overflow": "hidden"
  81. })
  82. }, 4000);
  83. if(click) {
  84. return false;
  85. } else {
  86. luck.speed = 100;
  87. roll();
  88. click = true;
  89. return false;
  90. }
  91. });
  92. };
  93. // 轮播图
  94. var swiper = new Swiper('.draw-container', {
  95. direction: "vertical",
  96. autoplay: true,
  97. loop: true,
  98. });
  99. //ios弹窗位置调整
  100. $("input").bind('focus', function() {
  101. var top = document.body.scrollTop;
  102. $(window).scrollTop(top);
  103. })
  104. $("input").bind('blur', function() {
  105. var top = document.body.scrollTop;
  106. $(window).scrollTop(top);
  107. })
  108. //关闭弹窗
  109. $(".close").on("click", function() {
  110. $(".cover").addClass("dis_no");
  111. $(".cover_box").addClass("dis_no");
  112. $("body,html").css({
  113. "height": "100%",
  114. "overflow": "auto"
  115. })
  116. })
  117. $("#form_insure").on("click", function() {
  118. $(".cover_box").addClass("dis_no");
  119. $(".result_box").removeClass("dis_no");
  120. $("body,html").css({
  121. "height": "100%",
  122. "overflow": "hidden"
  123. })
  124. })
  125. </script>