avatar

目录
大转盘
html
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<template>

<div>
<BaseHeader title="大转盘" go_back="1" />
<div class="black_hr">div>
<div class="turntable-bg rotateBg">
<div class="parent_box">
<div class="pointer">
<img src="@/assets/img/pointer.png" alt="pointer" @click="handleRotate" />
div>
<div class="rotate">
<img
id="rotate"
src="@/assets/img/turntable2.png"
alt="turntable"
:style="{transform:rotate_deg,transition:rotate_transition}"
/>
div>
div>
div>
div>
template>
<script>
import BaseHeader from "@/components/public/BaseHeader";
export default {
data() {
return {
cat: 360 / 7, //总共8个扇形区域,每个区域约45度
isAllowClick: true, //是否能够点击
start_rotating_deg: 0, //初始旋转角度
rotate_deg: 0, //将要旋转的角度
rotate: 0, //实际偏移角度
rotate_angle: 0,
rotate_transition: "transform 3s ease-in-out" //初始化选中的过度属性控制
};
},
components: {
BaseHeader
},
created() {},
methods: {
handleRotate() {
this.isAllowClick = true;
this.rotating();
},
rotating() {
let _this = this;
if (!this.isAllowClick) return;
this.isAllowClick = false;
var rand_circle = 5; //默认多旋转5圈
var randomDeg = Math.floor(Math.random() * 360); //获取0到359之间的随机度数
var deg =
this.start_rotating_deg +
rand_circle * 360 +
randomDeg -
(this.start_rotating_deg % 360); //将要旋转的度数
this.start_rotating_deg = deg; //下一次旋转的开始度数
this.rotate_deg = "rotate(" + deg + "deg)";
this.rotate = deg % 360; //实际偏移的度数
var that = this;
setTimeout(function() {
that.isAllowClick = true;
if (that.rotate <= that.cat * 1) {
_this.$toast("恭喜您,获得1等奖");
} else if (that.rotate <= that.cat * 2) {
_this.$toast("恭喜您,获得2等奖");
} else if (that.rotate <= that.cat * 3) {
_this.$toast("恭喜您,获得3等奖");
} else if (that.rotate <= that.cat * 4) {
_this.$toast("恭喜您,获得4等奖");
} else if (that.rotate <= that.cat * 5) {
_this.$toast("恭喜您,获得5等奖");
} else if (that.rotate <= that.cat * 6) {
_this.$toast("恭喜您,获得6等奖");
} else if (that.rotate <= that.cat * 7) {
_this.$toast("再接再厉哦!");
// } else if (that.rotate <= that.cat * 8) {
// _this.$toast("恭喜您,获得1等奖");
}
}, 3500);
}
}
};
script>
<style lang="less" scoped>
.turntable-bg {
height: 100vh;
position: relative;
.parent_box {
width: 100vw;
height: 100vw;
position: relative;
}
.pointer {
width: 66px;
height: 100px;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-55%, -50%);
z-index: 8;
img {
width: 100%;
}
}
.rotate {
position: absolute;
padding: 20%;
img {
width: 100%;
}
}
}
style>

监听:Transition 结束

javascript
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
 mounted() {
/**
* 监听:Transition 结束
*/
// let $target = document.getElementsByClassName("item_box")[0];
let $target = this.$refs.item_box;
var transitions = {
transition: "transitionend",
OTransition: "oTransitionEnd",
MozTransition: "transitionend",
WebkitTransition: "webkitTransitionEnd"
};

var eventName = undefined;
for (let t in transitions) {
if ($target.style[t] !== undefined) {
eventName = transitions[t];
break;
}
}

eventName &&
$target.addEventListener(eventName, function() {
alert("Transition end!");
});
},
`
文章作者: 会吃鱼的猫
文章链接: https://lovecatdog.github.io/2020/03/13/%E5%A4%A7%E8%BD%AC%E7%9B%98/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 LoveCatDog
打赏
  • 微信
    微信
  • 支付宝
    支付宝

评论
简体中文