Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the Gongge rotation lucky draw by vue

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Editor to share with you how to achieve the vue Gongge rotation lottery, I hope you will gain something after reading this article, let's discuss it together!

Vue realizes Gongge rotation lottery (similar to xx reincarnation crossing the line of fire), for your reference, the details are as follows

Don't do too much commentary, just go to the code. The key code is annotated and easy to understand. Copy directly and you can use it!

In addition, part of css depends on node-sass and sass-loader. If it is not installed, the existing partners will skip it directly.

"node-sass": "^ 4.12.0"

"sass-loader": "^ 8.0.2"

{{item.label}} {{item.label}} export default {name: "Luck" Data () {return {list: [{label: "not winning", val: 1, img: ", index: 0, active: false}, {label:" Great 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 points", 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: "Amousi yoghurt", val: 10, img: ", index: 9, active: false}, {label:" emptying shopping cart ", val: 11, img:", index: 10, active: false} {label: "50 yuan phone fee", val: 12, img: ", index: 11, active: false},], isAnimate: false, / / the representative is drawing a lottery when it is true Clicking the lucky draw button before the end of the current lottery is invalid jumpIndex: Math.floor (Math.random () * 12), / / the index jumpingTime: 0, / / the time of the round jump jumpingTotalTime: 0, / the total time of the round jump, based on the duration variable plus a random number between 0,1000 to form the jumpingChange: 0, / / the peak rate of the round-robin Based on the velocity variable plus a random number between 0,3, duration: 4500, / / duration velocity: 4500, / / rate} }, 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; / / time spent executing the setTimeout method per frame / / if the current time is greater than the total time, exit the animation and liquidate the prize if (this.jumpingTime > = this.jumpingTotalTime) {this.isAnimate = false If (index = = 0) {alert (`I 'm sorry I didn't get the prize, keep up my efforts);} else {alert (`Congratulations on getting: ${this.list [index] .label} `)} return} / / rotation training animation if (index > = this.list.length-1) {index = 0 This.list [11] .active = false; this.list [index] .active = true; index-= 1;} else {this.list.active = false; this.list [index + 1] .active = true;} setTimeout (() = > {this.animateRound (index + 1);}, this.easeOut (this.jumpingTime, 0, this.jumpingChange, this.jumpingTotalTime)) }, / * slow 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;},},}; .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 draw"; 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;}}

Effect picture:

After reading this article, I believe you have a certain understanding of "how vue realizes the Gongge rotation lucky draw". If you want to know more about it, welcome to follow the industry information channel, thank you for your reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report