vuejs可以做转盘,其实现方法:1、创建抽奖按钮;2、获取转盘应该停止的位置;3、与后台交互;4、在动画结束后停在步骤2设置的地方;5、设置提示中奖解锁功能。
本文操作环境:windows7系统、Vue2.9.6版、Dell G3电脑。
vuejs 可以做转盘吗?
Vue中可配置的圆形抽奖转盘组件
import roundTurntable from './components/roundTurntable';
components: { roundTurntable },
<round-turntable ref="roundTurntable" :prizeData="prizeData" :rotateCircle="rotateCircle" :duringTime="duringTime" :turntableStyleOption="turntableStyleOption" @endRotation="endRotation" class="turntable"> <template slot="item" slot-scope="scope"> <p class="turntable-name">{{ scope.item.prizeName }}</p> <p class="turntable-img"> @@##@@ </p> </template> </round-turntable>
data() { return { // 转盘上的奖品数据 prizeData: [ { id: 1, prizeName: '2000元京东券', prizeImg: 'http://demo.sc.chinaz.net/Files/DownLoad/webjs1/201803/jiaoben5789/images/1.png', }, { id: 2, prizeName: '300元京东券', prizeImg: 'http://demo.sc.chinaz.net/Files/DownLoad/webjs1/201803/jiaoben5789/images/7.png', }, { id: 3, prizeName: '50个比特币', prizeImg: 'http://demo.sc.chinaz.net/Files/DownLoad/webjs1/201803/jiaoben5789/images/3.png', }, { id: 4, prizeName: '50元话费券', prizeImg: 'http://demo.sc.chinaz.net/Files/DownLoad/webjs1/201803/jiaoben5789/images/4.png', }, { id: 5, prizeName: '100元话费券', prizeImg: 'http://demo.sc.chinaz.net/Files/DownLoad/webjs1/201803/jiaoben5789/images/5.png', }, { id: 6, prizeName: '100个比特币', prizeImg: 'http://demo.sc.chinaz.net/Files/DownLoad/webjs1/201803/jiaoben5789/images/6.png', } ], // 转动的圈数 rotateCircle: 6, // 转动需要持续的时间(s) duringTime: 4.5, // 转盘样式的选项 turntableStyleOption: { // 背景色 prizeBgColors: ['#AE3EFF', '#4D3FFF', '#FC262C', '#3A8BFF', '#EE7602', '#FE339F'], // 转盘的外边框颜色 borderColor: '#199301', }, } }, methods: { // 已经转动完转盘触发的函数 endRotation() { // 提示中奖 alert(`恭喜您获奖啦,您的奖品是:${this.prizeData[this.prizeIndex].prizeName}`); }, },
.turntable { position: absolute; left: calc(50% - 200px); top: calc(50% - 200px); width: 400px; height: 400px; } .turntable-name { /*background: pink;*/ position: absolute; left: 10px; top: 20px; width: calc(100% - 20px); font-size: 26px; text-align: center; color: #fff; } .turntable-img { position: absolute; /*要居中就要50% - 宽度 / 2*/ left: calc(50% - 80px / 2); top: 60px; width: 80px; height: 80px; img { display: inline-block; width: 100%; height: 100%; } }
参数 | 说明 | 类型 | 默认值 |
---|---|---|---|
ref | 获取这组件的dom节点,调用子组件的开始转动动画方法要用到this.$refs[refName].rotate(index) | string | — |
prizeData | 显示在转盘上的奖品数据 | array | — |
rotateCircle | 转盘要转过的圈数 | number | 6 |
duringTime | 转动需要持续的时间(单位为秒s) | number | 4.5 |
turntableStyleOption | 转盘的样式选项(背景色、外边框颜色) | object | { prizeBgColors: ['#AE3EFF', '#4D3FFF', '#FC262C', '#3A8BFF', '#EE7602', '#FE339F'], borderColor: '#199301' } |
class | 用来定义转盘位置和大小的样式 | string | — |
事件名称 | 说明 | 回调参数 |
---|---|---|
endRotation | 转盘停下来后触发的事件回调 | — |
https://github.com/LiaPig/vue-round-turntable
立即学习“前端免费学习笔记(深入)”;
http://sc.chinaz.com/jiaobendemo.aspx?downloadid=12018113053246
以上就是vuejs 可以做转盘吗的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号