1. //html
    2. <div class="all clearfix">
    3. <div class="title"></div>
    4. <div class="information"></div>
    5. <div class="drawBox">
    6. <ul>
    7. <li v-for="(item, index) in noticeList" :key="index">
    8. <img :src="item.pri" alt="" />
    9. </li>
    10. </ul>
    11. <div class="buttom"></div>
    12. </div>
    13. //复制一遍作为蒙板
    14. <div class="drawBox">
    15. <ul>
    16. <li
    17. v-for="(item, i) in noticeList"
    18. :class="i == index ? 'on' : ''"
    19. :key="i"
    20. ></li>
    21. </ul>
    22. <div class="buttom" @click="turnToFn"></div>
    23. </div>
    24. </div>
    1. js
    2. data(){
    3. return{
    4. index: 0, // 当前转动到哪个位置,起点位置
    5. count: 8, // 总共有多少个位置
    6. timer: 0, // 每次转动定时器
    7. speed: 200, // 初始转动速度
    8. times: 0, // 转动次数
    9. cycle: 50, // 转动基本次数:即至少需要转动多少次再进入抽奖环节
    10. prize: -1, // 中奖位置
    11. }
    12. }
    13. methods:{
    14. /**
    15. * 大转盘
    16. * * */
    17. turnToFn: function () {
    18. console.log("asdas");
    19. this.speed = 200; //每次抽奖速度初始化为200
    20. this.prize = 3; //中奖位置赋值,跑马灯最终停留位置,这里实际位置需要-1
    21. this.startRoll(); //执行抽奖
    22. },
    23. startRoll() {
    24. this.times += 1; // 转动次数
    25. this.oneRoll(); // 转动过程调用的每一次转动方法,这里是第一次调用初始化
    26. this.usePrize();
    27. },
    28. // 每一次转动
    29. oneRoll() {
    30. let index = this.index; // 当前转动到哪个位置
    31. const count = 8; // 总共有多少个位置
    32. index += 1;
    33. if (index > count - 1) {
    34. index = 0;
    35. }
    36. this.index = index;
    37. },
    38. usePrize(){
    39. // 如果当前转动次数达到要求 && 目前转到的位置是中奖位置
    40. if (this.times > this.cycle +10 && this.prize === this.index) {
    41. clearTimeout(this.timer); // 清除转动定时器
    42. clearTimeout(this.lamp); // 清除灯光定时器
    43. this.lampShow = false; // 白色灯隐藏
    44. this.times = 0; // 转动跑格子次数初始化为0,可以开始下次抽奖
    45. } else {
    46. if(this.times < this.cycle -20){
    47. this.speed -= 4; // 加快转动速度
    48. }else{
    49. this.speed += 10; // 抽奖即将结束,放慢转动速度
    50. }
    51. this.timer = setTimeout(this.startRoll, this.speed);//开始转动
    52. }
    53. },
    54. }