Vue implements the palace grid rotation lottery (similar to the xx reincarnation of CrossFire), for your reference, the specific content is as follows Without further explanation, let's get straight to the code. The key codes are commented and easy to understand. Just copy and use!
<template> <div class="home"> <div class="home-container"> <div class="home-container-line"> <div class="home-container-line-box" v-for="item in list.slice(0, 5)" :key="item.index" :class="{ selected: item.active }" > {{ item.label }} </div> </div> <div class="home-container-line"> <div class="home-container-line-box" v-for="item in list.slice(11, 12)" :key="item.index" :class="{ selected: item.active }" > {{ item.label }} </div> <div class="home-container-line-btn" @click="handleClick" :disable="isAnimate"></div> <div class="home-container-line-box" v-for="item in list.slice(5, 6)" :key="item.index" :class="{ selected: item.active }" > {{ item.label }} </div> </div> <div class="home-container-line"> <div class="home-container-line-box" v-for="item in Array.prototype.reverse.call(list.slice(6, 11))" :key="item.index" :class="{ selected: item.active }" > {{ item.label }} </div> </div> </div> </div> </template> <script> export default { name: "Luck", data() { return { list: [ { label: "Not winning", val: 1, img: "", index: 0, active: false }, { label: "Health Care", val: 2, img: "", index: 1, active: false }, { label: "iPhone13", val: 3, img: "", index: 2, active: false }, { label: "MacBook Pro", val: 4, img: "", index: 3, active: false }, { label: "MacBook Air", val: 5, img: "", index: 4, active: false }, { label: "1 point", val: 6, img: "", index: 5, active: false }, { label: "5 points", val: 7, img: "", index: 6, active: false }, { label: "10 points", val: 8, img: "", index: 7, active: false }, { label: "Xiao Ai", val: 9, img: "", index: 8, active: false }, { label: "Anmuxi Yogurt", val: 10, img: "", index: 9, active: false }, { label: "Clear shopping cart", val: 11, img: "", index: 10, active: false }, { label: "50 yuan phone bill", val: 12, img: "", index: 11, active: false }, ], isAnimate: false, // true means the lottery is in progress. Clicking the lottery button before the current lottery ends is invalid jumpIndex: Math.floor(Math.random() * 12), // Index of the lottery jump jumpingTime: 0, // Time of the jump jumpingTotalTime: 0, // Total jump time, based on the duration variable plus a random number between 0 and 1000 jumpingChange: 0, // Peak jump rate, based on the velocity variable plus a random number between 0 and 3 duration: 4500, // Duration velocity: 300, // Velocity}; }, methods: { handleClick() { if(this.isAnimate) return; this.jumpingTime = 0; this.jumpingTotalTime = Math.random() * 1000 + this.duration; this.jumpingChange = Math.random() * 3 + this.velocity; this.animateRound(this.jumpIndex); }, animateRound(index) { this.isAnimate = true; if(this.jumpIndex < this.list.length - 1 ) this.jumpIndex ++; if (this.jumpIndex >= this.list.length - 1 ) this.jumpIndex = 0; this.jumpingTime += 100; // The time consumed by executing the setTimeout method in each frame // If the current time is greater than the total time, exit the animation and clear the prize if (this.jumpingTime >= this.jumpingTotalTime) { this.isAnimate = false; if(index == 0) { alert(`It's a pity that I didn't win the prize, keep up the good work~`); } else{ alert(`Congratulations, you have drawn: ${this.list[index].label}`) } return } // Rotation animation if (index >= this.list.length-1) { index = 0; this.list[11].active = false; this.list[index].active = true; index -= 1; } else { this.list[index].active = false; this.list[index + 1].active = true; } setTimeout(() => { this.animateRound(index + 1); }, this.easeOut(this.jumpingTime, 0, this.jumpingChange, this.jumpingTotalTime)); }, /** * Easing function, from fast to slow* @param {Num} t current time* @param {Num} b initial value* @param {Num} c change value* @param {Num} d duration*/ easeOut(t, b, c, d) { if ((t /= d / 2) < 1) return (c / 2) * t * t + b; return (-c / 2) * (--t * (t - 2) - 1) + b; }, }, }; </script> <style lang="scss" scoped> .center { display: flex; justify-content: center; align-items: center; } .home { padding: 0; margin: 0; width: 100%; height: calc(100vh - 16px); background-image: linear-gradient(25deg, #30007c, #464995, #4d83ad, #41bfc4); @extend .center; &-container { width: 1000px; height: 600px; &-line { width: 100%; height: 198px; display: flex; &-box { flex: 1; overflow: hidden; margin: 5px 3px 5px 3px; @extend .center; background: #fff; transition: all .3s; } &-btn { position: relative; flex: 3; overflow: hidden; margin: 5px 3px 3px 3px; @extend .center; box-shadow: 0 1px 10px 0px #cf5531; background-image: linear-gradient( 25deg, #cf5531, #d0853a, #cdaf43, #c4d84d ); cursor: pointer; &:active { background-image: linear-gradient( 25deg, #3f3e41, #6d6340, #9a8b39, #c9b629 ); } &::before { position: absolute; content: "Click to win the prize"; font-size: 2.5rem; color: #fff; font-weight: bold; } } } } } .selected { background: rgba($color: #f6e58d, $alpha: 0.5); animation-name: twinkle; animation-duration: 3s; animation-iteration-count: infinite; } @keyframes twinkle { 0% {background:#ffbe76;} 100% {background:#f6e58d;} } </style> Effect picture: Finally, I would like to point out that the probability is completely random. There is no particularly good idea to adjust the probability of winning at present. If you have better ideas, you are welcome to discuss it together. The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: The difference between method=post/get in Form
>>: What are your principles for designing indexes? How to avoid index failure?
#include <asm/io.h> #define ioremap(cookie,...
Chinese Tutorial https://www.ncnynl.com/category/...
The fixed IP address of the centos-DVD1 version s...
This article example shares the specific code of ...
Everyone knows that data in MySQL needs to be wri...
Table of contents introduction Distinguish betwee...
The following are all performed on my virtual mac...
1. Download the RPM package corresponding to Linu...
1. Requirements When using the Vue.js framework t...
Start the centos8 virtual machine and press the u...
Preface Speaking of text search tools, everyone m...
Statistics of QPS values in the last N seconds ...
Table of contents 2. Field concatenation 2. Give ...
This article shares the specific code of js to ac...
Linux installation MySQL notes 1. Before installi...