WeChat Open Platform

Mini Programs Documentation

Accelerometer

wx.onAccelerometerChange(CALLBACK)

Monitors acceleration data, frequency: 5 times/second, will automatically start monitoring after interface debugging, wx.stopAccelerometer can be used to stop monitoring.

CALLBACK return parameters:

Parameter Type Description
x Number X-axis
y Number Y-axis
z Number Z-axis

Sample code:

wx.onAccelerometerChange(function(res) {
  console.log(res.x)
  console.log(res.y)
  console.log(res.z)
})

wx.startAccelerometer(OBJECT)

Starts monitoring acceleration data.

OBJECT parameter descriptions:

Parameter Type Required Description
success Function No Callback function for successful interface call
fail Function No Callback function for failed interface call
complete Function No Callback function for interface call results (will be executed if call succeeds or fails)

Sample code:

wx.startAccelerometer()

wx.stopAccelerometer(OBJECT)

Stops monitoring acceleration data.

OBJECT parameter descriptions:

Parameter Type Required Description
success Function No Callback function for successful interface call
fail Function No Callback function for failed interface call
complete Function No Callback function for interface call results (will be executed if call succeeds or fails)

Sample code:

wx.stopAccelerometer()