欢迎光临
我们一直在努力

九八云百度小程序教程:swan.startDeviceMotionListening

  • swan.startDeviceMotionListening
    • 方法参数
      • object 参数说明
      • interval 的有效值
    • 示例
      • 图片示例
      • 代码示例

    swan.startDeviceMotionListening

    基础库 3.30.2 开始支持,低版本需做兼容处理。

    解释:开始监听设备方向的变化。
    Web 态说明:由于浏览器对于 W3C 规范的实现差异,startDeviceMotionListening 功能在部分浏览器(比如 Safari 浏览器)下不可用,在功能不可用的情况下会执行开发者设置的 fail 回调

    方法参数

    Object object

    object 参数说明

    属性名 类型 必填 默认值 说明

    interval

    String

    normal

    监听设备方向的变化回调函数的执行频率

    success

    Function

    接口调用成功的回调函数

    fail

    Function

    接口调用失败的回调函数

    complete

    Function

    接口调用结束的回调函数(调用成功、失败都会执行)

    interval 的有效值

    根据机型性能、当前 CPU 与内存的占用情况,interval 的设置与实际 swan.onAccelerometerChange() 回调函数的执行频率会有一些出入。

    说明

    game

    适用于更新游戏的回调频率,在 20ms/次 左右

    ui

    适用于更新 UI 的回调频率,在 60ms/次 左右

    normal

    普通的回调频率,在 200ms/次 左右

    示例

    跳转编辑工具

    在开发者工具中打开

    在 WEB IDE 中打开

    扫码体验

    代码示例

    请使用百度APP扫码

    图片示例

    代码示例

    • SWAN
    • JS
    
     
    1. <view class="wrap">
    2. <view class="card-area">
    3. <view class="list-area border-bottom" s-for="item in infoList">
    4. <text class="list-item-key-4">{{item.chineseName}}</text>
    5. <text class="list-item-value">{{item.value}}</text>
    6. </view>
    7. <view class="button-group">
    8. <button bind:tap="stopDeviceMotionListening" disabled="{{!disabled}}" type="primary" hover-stop-propagation="true">停止监听</button>
    9. <button bind:tap="startDeviceMotionListening" disabled="{{disabled}}" type="primary" hover-stop-propagation="true">开始监听</button>
    10. </view>
    11. </view>
    12. </view>

    赞(0) 打赏
    未经允许不得转载:九八云安全 » 九八云百度小程序教程:swan.startDeviceMotionListening

    评论 抢沙发