Skip to content

Commit 5991910

Browse files
committed
fix: 完成一次摇一摇 返回上一个页面 开启监听加速度 晃动手机摇一摇还有声音
1 parent 79ca100 commit 5991910

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

platforms/app-plus/shake/shake.vue

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
data() {
1414
return {
1515
img: 'https://img-cdn-qiniu.dcloud.net.cn/uniapp/shake/1.jpg',
16-
show: false
16+
show: false,
17+
isOpened: false
1718
}
1819
},
1920
onLoad: function () {
@@ -23,7 +24,7 @@
2324
let index = 1,
2425
t = null;
2526
uni.onAccelerometerChange((res) => {
26-
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) {
2728
music.play();
2829
setTimeout(() => {
2930
index++;
@@ -43,8 +44,12 @@
4344
}
4445
})
4546
},
47+
onShow() {
48+
this.isOpened = true;
49+
},
4650
onUnload() {
4751
this.show = false;
52+
this.isOpened = false;
4853
uni.stopAccelerometer();
4954
}
5055
}

0 commit comments

Comments
 (0)