my.vibrate(OBJECT)
说明:mPaaS 10.1.60 及以上版本支持该接口。
此接口用于调用振动功能。
代码示例
// API-DEMO page/API/vibrate/vibrate.json{"defaultTitle": "Vibrate"}
<!-- API-DEMO page/API/vibrate/vibrate.axml--><view class="page"><button type="primary" onTap="vibrate">开始振动</button><button type="primary" onTap="vibrateLong">长时间振动 (400ms)</button><button type="primary" onTap="vibrateShort">短时间振动 (40ms)</button></view>
// API-DEMO page/API/vibrate/vibrate.jsPage({vibrate() {my.vibrate({success: () => {my.alert({ title: '振动起来了'});}});},vibrateLong() {if (my.canIUse('vibrateLong')) {my.vibrateLong((res) => { });} else {my.alert({title: '客户端版本过低',content: 'my.vibrateLong() 需要 10.1.35 及以上版本'});}},vibrateShort() {if (my.canIUse('vibrateShort')) {my.vibrateShort((res) => { });} else {my.alert({title: '客户端版本过低',content: 'my.vibrateShort() 需要 10.1.35 及以上版本'});}}});
my.vibrateLong(OBJECT)
说明:mPaaS 10.1.60 及以上版本支持该接口。
较长时间的振动(400 ms)。
代码示例
// API-DEMO page/API/vibrate/vibrate.json{"defaultTitle": "Vibrate"}
<!-- API-DEMO page/API/vibrate/vibrate.axml--><view class="page"><button type="primary" onTap="vibrate">开始振动</button><button type="primary" onTap="vibrateLong">长时间振动 (400ms)</button><button type="primary" onTap="vibrateShort">短时间振动 (40ms)</button></view>
// API-DEMO page/API/vibrate/vibrate.jsPage({vibrate() {my.vibrate({success: () => {my.alert({ title: '振动起来了'});}});},vibrateLong() {if (my.canIUse('vibrateLong')) {my.vibrateLong((res) => { });} else {my.alert({title: '客户端版本过低',content: 'my.vibrateLong() 需要 10.1.35 及以上版本'});}},vibrateShort() {if (my.canIUse('vibrateShort')) {my.vibrateShort((res) => { });} else {my.alert({title: '客户端版本过低',content: 'my.vibrateShort() 需要 10.1.35 及以上版本'});}}});
my.vibrateShort(OBJECT)
说明:mPaaS 10.1.60 及以上版本支持该接口。
较短时间的振动(40 ms)。
代码示例
// API-DEMO page/API/vibrate/vibrate.json{"defaultTitle": "Vibrate"}
<!-- API-DEMO page/API/vibrate/vibrate.axml--><view class="page"><button type="primary" onTap="vibrate">开始振动</button><button type="primary" onTap="vibrateLong">长时间振动 (400ms)</button><button type="primary" onTap="vibrateShort">短时间振动 (40ms)</button></view>
// API-DEMO page/API/vibrate/vibrate.jsPage({vibrate() {my.vibrate({success: () => {my.alert({ title: '振动起来了'});}});},vibrateLong() {if (my.canIUse('vibrateLong')) {my.vibrateLong((res) => { });} else {my.alert({title: '客户端版本过低',content: 'my.vibrateLong() 需要 10.1.35 及以上版本'});}},vibrateShort() {if (my.canIUse('vibrateShort')) {my.vibrateShort((res) => { });} else {my.alert({title: '客户端版本过低',content: 'my.vibrateShort() 需要 10.1.35 及以上版本'});}}});
该文章对您有帮助吗?