All Products
Search
Document Center

Vibrate

Last Updated: Feb 05, 2021

my.vibrate(OBJECT)

This API is supported in mPaaS 10.1.60 and later versions.

This API is used to call the vibration function.

Code sample

 
  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. Start vibrating
  5. </button>
  6. <button type="primary" onTap="vibrateLong">
  7. Long vibration (400ms)
  8. </button>
  9. <button type="primary" onTap="vibrateShort">
  10. Short vibration (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: 'Vibrating'});
  7. }
  8. });
  9. },
  10. vibrateLong() {
  11. if (my.canIUse('vibrateLong')) {
  12. my.vibrateLong((res) => { });
  13. } else {
  14. my.alert({
  15. title: 'Client version is too low',
  16. content: 'my.vibrateLong() requires 10.1.35 and later versions'
  17. });
  18. }
  19. },
  20. vibrateShort() {
  21. if (my.canIUse('vibrateShort')) {
  22. my.vibrateShort((res) => { });
  23. } else {
  24. my.alert({
  25. title: 'Client version is too low',
  26. content: 'my.vibrateShort() requires 10.1.35 and later versions'
  27. });
  28. }
  29. }
  30. });

my.vibrateLong(OBJECT)

This API is supported in mPaaS 10.1.60 and later versions.

Long vibration (400 ms).

Code sample

 
  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. Start vibrating
  5. </button>
  6. <button type="primary" onTap="vibrateLong">
  7. Long vibration (400ms)
  8. </button>
  9. <button type="primary" onTap="vibrateShort">
  10. Short vibration (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: 'Vibrating'});
  7. }
  8. });
  9. },
  10. vibrateLong() {
  11. if (my.canIUse('vibrateLong')) {
  12. my.vibrateLong((res) => { });
  13. } else {
  14. my.alert({
  15. title: 'Client version is too low',
  16. content: 'my.vibrateLong() requires 10.1.35 and later versions'
  17. });
  18. }
  19. },
  20. vibrateShort() {
  21. if (my.canIUse('vibrateShort')) {
  22. my.vibrateShort((res) => { });
  23. } else {
  24. my.alert({
  25. title: 'Client version is too low',
  26. content: 'my.vibrateShort() requires 10.1.35 and later versions'
  27. });
  28. }
  29. }
  30. });

my.vibrateShort(OBJECT)

This API is supported in mPaaS 10.1.60 and later versions.

Short vibration (40 ms).

Code sample

 
  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. Start vibrating
  5. </button>
  6. <button type="primary" onTap="vibrateLong">
  7. Long vibration (400ms)
  8. </button>
  9. <button type="primary" onTap="vibrateShort">
  10. Short vibration (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: 'Vibrating'});
  7. }
  8. });
  9. },
  10. vibrateLong() {
  11. if (my.canIUse('vibrateLong')) {
  12. my.vibrateLong((res) => { });
  13. } else {
  14. my.alert({
  15. title: 'Client version is too low',
  16. content: 'my.vibrateLong() requires 10.1.35 and later versions'
  17. });
  18. }
  19. },
  20. vibrateShort() {
  21. if (my.canIUse('vibrateShort')) {
  22. my.vibrateShort((res) => { });
  23. } else {
  24. my.alert({
  25. title: 'Client version is too low',
  26. content: 'my.vibrateShort() requires 10.1.35 and later versions'
  27. });
  28. }
  29. }
  30. });