点击按钮调接口,当返回奖品index时,使转盘转出相应的角度。动效是利用了transition过渡动画。
当奖品是固定的时候,就少了绘制奖品转盘的步骤。否则得绘制奖品转盘。
dom
1 2 3 4 5 6
| <div class="turn-wrapper"> <div class="panel" :style="rotateStyle"></div> <div class="pointer" @click="rotateHandle"></div> </div>
|
js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| export default { computed: { rotateStyle() { return ` transition: transform 5000ms ease; transform: rotate(${this.rotateAngle}deg) ` } }, data() { return { isRotating: false, rotateAngle: 0, angleList: [], bingoNum: 2, } }, mounted() { const average = 360 / 8 for (let i = 0; i < 8; i++) { this.angleList.push(i * average + average / 2) } }, methods: { rotateHandle() { if (this.isRotating) { return } this.beginRotate(index) }, beginRotate(index) { const { rotateAngle, angleList } = this this.isRotating = true const angle = rotateAngle + 5 * 360 + angleList[index] - rotateAngle % 360 this.rotateAngle = angle
setTimeout(() => { this.isRotating = false }, 5000) } } }
|