支付寶小程序API 震動(dòng)

2020-09-15 11:25 更新

my.vibrate

更新時(shí)間:2020-09-14 18:14:07

簡介

my.vibrate 是調(diào)用振動(dòng)功能的 API。

掃碼體驗(yàn)

振動(dòng).jpeg

效果示例

振動(dòng).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. 開始振動(dòng)
  5. </button>
  6. <button type="primary" onTap="vibrateLong">
  7. 長時(shí)間振動(dòng) (400ms)
  8. </button>
  9. <button type="primary" onTap="vibrateShort">
  10. 短時(shí)間振動(dòng) (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: '振動(dòng)起來了'});
  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 是調(diào)用觸發(fā)較長時(shí)間的振動(dòng) (400ms)的 API。

掃碼體驗(yàn)

振動(dòng).jpeg

效果示例

400s振動(dòng).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. 開始振動(dòng)
  5. </button>
  6. <button type="primary" onTap="vibrateLong">
  7. 長時(shí)間振動(dòng) (400ms)
  8. </button>
  9. <button type="primary" onTap="vibrateShort">
  10. 短時(shí)間振動(dòng) (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: '振動(dòng)起來了'});
  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 是調(diào)用觸發(fā)較短時(shí)間的振動(dòng) (40ms)的 API。

使用限制

僅在 iPhone 7 / 7 Plus 以上及 Android 機(jī)型生效。

掃碼體驗(yàn)

振動(dòng).jpeg

效果示例

40s振動(dòng).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. 開始振動(dòng)
  5. </button>
  6. <button type="primary" onTap="vibrateLong">
  7. 長時(shí)間振動(dòng) (400ms)
  8. </button>
  9. <button type="primary" onTap="vibrateShort">
  10. 短時(shí)間振動(dòng) (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: '振動(dòng)起來了'});
  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. });
以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號