Skip to main content
Version: Next

Taro.onDeviceMotionChange(callback)

Listens on the device orientation change event. The frequency is based on the Taro.startDeviceMotionListening() interval parameter. You can use Taro.stopDeviceMotionListening() stop listening.

Reference

Type

(callback: Callback) => void

Parameters

Callback

The callback function for the device orientation change event.

(result: CallbackResult) => void
PropertyType
resultCallbackResult

CallbackResult

PropertyTypeDescription
alphanumberWhen the phone coordinate X/Y and the earth coordinate X/Y coincide, the angle of rotation around the Z axis is alpha. The range is [0, 2*PI). It is positive when the phone rotates counterclockwise.
betanumberWhen the phone coordinate Y/Z and the earth coordinate Y/Z coincide, the angle of rotation around the X axis is beta. The range is [-1*PI, PI). It is positive when the phone rotates with its top toward the earth surface or the user.
gammanumberWhen the phone coordinate X/Z and the earth coordinate X/Z coincide, the angle of rotation around the Y axis is gamma. The range is [-1*PI/2, PI/2). It is positive when the phone rotates with its right side toward the earth surface.

API Support

APIWeChat Mini-ProgramH5React Native
Taro.onDeviceMotionChange✔️✔️✔️