支付宝小程序API 震动

2020-09-15 11:25 更新

my.vibrate

更新时间:2020-09-14 18:14:07

简介

my.vibrate 是调用振动功能的 API。

扫码体验

振动.jpeg

效果示例

振动.gif

示例代码

// 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.js
Page({
  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

简介

my.vibrateLong 是调用触发较长时间的振动 (400ms)的 API。

扫码体验

振动.jpeg

效果示例

400s振动.gif

示例代码

// 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.js
Page({
  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

简介

my.vibrateShort 是调用触发较短时间的振动 (40ms)的 API。

使用限制

仅在 iPhone 7 / 7 Plus 以上及 Android 机型生效。

扫码体验

振动.jpeg

效果示例

40s振动.gif

示例代码

// 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.js
Page({
  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 及以上版本'
      });
    }
  }
});
以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号