支付宝小程序API 震动

2020-09-15 11:25 更新

my.vibrate

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

简介

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

扫码体验

振动.jpeg

效果示例

振动.gif

示例代码

  1. // API-DEMO page/API/vibrate/vibrate.json
  2. {
  3. "defaultTitle": "Vibrate"
  4. }
  1. <!-- API-DEMO page/API/vibrate/vibrate.axml-->
  2. <view class="page">
  3. <button type="primary" onTap="vibrate">
  4. 开始振动
  5. </button>
  6. <button type="primary" onTap="vibrateLong">
  7. 长时间振动 (400ms)
  8. </button>
  9. <button type="primary" onTap="vibrateShort">
  10. 短时间振动 (40ms)
  11. </button>
  12. </view>
  1. // API-DEMO page/API/vibrate/vibrate.js
  2. Page({
  3. vibrate() {
  4. my.vibrate({
  5. success: () => {
  6. my.alert({ title: '振动起来了'});
  7. }
  8. });
  9. },
  10. vibrateLong() {
  11. if (my.canIUse('vibrateLong')) {
  12. my.vibrateLong((res) => { });
  13. } else {
  14. my.alert({
  15. title: '客户端版本过低',
  16. content: 'my.vibrateLong() 需要 10.1.35 及以上版本'
  17. });
  18. }
  19. },
  20. vibrateShort() {
  21. if (my.canIUse('vibrateShort')) {
  22. my.vibrateShort((res) => { });
  23. } else {
  24. my.alert({
  25. title: '客户端版本过低',
  26. content: 'my.vibrateShort() 需要 10.1.35 及以上版本'
  27. });
  28. }
  29. }
  30. });

my.vibrateLong

简介

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

扫码体验

振动.jpeg

效果示例

400s振动.gif

示例代码

  1. // API-DEMO page/API/vibrate/vibrate.json
  2. {
  3. "defaultTitle": "Vibrate"
  4. }
  1. <!-- API-DEMO page/API/vibrate/vibrate.axml-->
  2. <view class="page">
  3. <button type="primary" onTap="vibrate">
  4. 开始振动
  5. </button>
  6. <button type="primary" onTap="vibrateLong">
  7. 长时间振动 (400ms)
  8. </button>
  9. <button type="primary" onTap="vibrateShort">
  10. 短时间振动 (40ms)
  11. </button>
  12. </view>
  1. // API-DEMO page/API/vibrate/vibrate.js
  2. Page({
  3. vibrate() {
  4. my.vibrate({
  5. success: () => {
  6. my.alert({ title: '振动起来了'});
  7. }
  8. });
  9. },
  10. vibrateLong() {
  11. if (my.canIUse('vibrateLong')) {
  12. my.vibrateLong((res) => { });
  13. } else {
  14. my.alert({
  15. title: '客户端版本过低',
  16. content: 'my.vibrateLong() 需要 10.1.35 及以上版本'
  17. });
  18. }
  19. },
  20. vibrateShort() {
  21. if (my.canIUse('vibrateShort')) {
  22. my.vibrateShort((res) => { });
  23. } else {
  24. my.alert({
  25. title: '客户端版本过低',
  26. content: 'my.vibrateShort() 需要 10.1.35 及以上版本'
  27. });
  28. }
  29. }
  30. });

my.vibrateShort

简介

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

使用限制

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

扫码体验

振动.jpeg

效果示例

40s振动.gif

示例代码

  1. // API-DEMO page/API/vibrate/vibrate.json
  2. {
  3. "defaultTitle": "Vibrate"
  4. }
  1. <!-- API-DEMO page/API/vibrate/vibrate.axml-->
  2. <view class="page">
  3. <button type="primary" onTap="vibrate">
  4. 开始振动
  5. </button>
  6. <button type="primary" onTap="vibrateLong">
  7. 长时间振动 (400ms)
  8. </button>
  9. <button type="primary" onTap="vibrateShort">
  10. 短时间振动 (40ms)
  11. </button>
  12. </view>
  1. // API-DEMO page/API/vibrate/vibrate.js
  2. Page({
  3. vibrate() {
  4. my.vibrate({
  5. success: () => {
  6. my.alert({ title: '振动起来了'});
  7. }
  8. });
  9. },
  10. vibrateLong() {
  11. if (my.canIUse('vibrateLong')) {
  12. my.vibrateLong((res) => { });
  13. } else {
  14. my.alert({
  15. title: '客户端版本过低',
  16. content: 'my.vibrateLong() 需要 10.1.35 及以上版本'
  17. });
  18. }
  19. },
  20. vibrateShort() {
  21. if (my.canIUse('vibrateShort')) {
  22. my.vibrateShort((res) => { });
  23. } else {
  24. my.alert({
  25. title: '客户端版本过低',
  26. content: 'my.vibrateShort() 需要 10.1.35 及以上版本'
  27. });
  28. }
  29. }
  30. });
以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号