1 parent 79ca100 commit 5991910Copy full SHA for 5991910
1 file changed
platforms/app-plus/shake/shake.vue
@@ -13,7 +13,8 @@
13
data() {
14
return {
15
img: 'https://img-cdn-qiniu.dcloud.net.cn/uniapp/shake/1.jpg',
16
- show: false
+ show: false,
17
+ isOpened: false
18
}
19
},
20
onLoad: function () {
@@ -23,7 +24,7 @@
23
24
let index = 1,
25
t = null;
26
uni.onAccelerometerChange((res) => {
- if (Math.abs(res.x) + Math.abs(res.y) + Math.abs(res.z) > 20 && !this.show) {
27
+ if (Math.abs(res.x) + Math.abs(res.y) + Math.abs(res.z) > 20 && !this.show && this.isOpened) {
28
music.play();
29
setTimeout(() => {
30
index++;
@@ -43,8 +44,12 @@
43
44
45
})
46
47
+ onShow() {
48
+ this.isOpened = true;
49
+ },
50
onUnload() {
51
this.show = false;
52
+ this.isOpened = false;
53
uni.stopAccelerometer();
54
55
0 commit comments