可以通过调用 wx.vibrateLong() 或 wx.vibrateShort() 方法,将小程序振动关闭。具体做法如下:
1. 在小程序的代码中找到需要关闭振动的页面或组件;
2. 在该页面或组件的js文件或wxml文件的script标签中,编写以下代码:
// 关闭长时间振动
wx.vibrateLong({
success: function () {
console.log("长时间振动已关闭");
},
fail: function () {
console.log("关闭长时间振动失败");
}
});
// 关闭短时间振动
wx.vibrateShort({
success: function () {
console.log("短时间振动已关闭");
},
fail: function () {
console.log("关闭短时间振动失败");
}
});
3. 添加以上代码后,保存并重新打开小程序即可。
注意,以上代码仅对当前页面或组件的振动进行关闭,如果需要关闭整个小程序的振动,可以在 app.js 文件中添加以下代码:
App({
onLaunch: function () {
wx.stopAccelerometer();
wx.offCompassChange();
wx.offDeviceMotionChange();
wx.offGyroscopeChange();
wx.offKeyboardHeightChange();
wx.stopHCE();
wx.offNetworkStatusChange();
wx.stopPullDownRefresh();
wx.offWindowResize();
wx.hideShareMenu();
wx.hideTabBarRedDot();
wx.hideTabBar();
wx.hideTabBar({
animation: true
});
}
});