文档

振动

更新时间:

my.vibrate(OBJECT)

说明:mPaaS 10.1.60 及以上版本支持该接口。


此接口用于调用振动功能。

代码示例

  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(OBJECT)

说明:mPaaS 10.1.60 及以上版本支持该接口。


较长时间的振动(400 ms)。

代码示例

  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(OBJECT)

说明:mPaaS 10.1.60 及以上版本支持该接口。


较短时间的振动(40 ms)。

代码示例

  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. });
  • 本页导读 (0)
文档反馈