Shake

更新时间:
复制 MD 格式

Detects shake gestures on a mobile device and triggers a callback each time the device is shaken.

my.watchShake(OBJECT)

Registers a shake gesture listener. Each call to my.watchShake registers a one-time listener: after the device is shaken, the callback is triggered. To continue listening for shake events, call my.watchShake again.

Sample code

// API-DEMO page/API/watch-shake/watch-shake.json
{
    "defaultTitle": "Shake"
}
<!-- API-DEMO page/API/watch-shake/watch-shake.axml-->
<view class="page">
  <button type="primary" onTap="watchShake">
   Bind Shake and click the Shake button to see the effect
  </button>
</view>
Page({
  watchShake() {
    my.watchShake({
      success: function() {
        console.log('Moved up')
        my.alert({ title:'Moved up o.o'});
      }
    });
  },
});