my.onDeviceMotionChange

Listen for device orientation change events.

Parameters

Type

Required

Description

Function listener

Yes

The function that listens for device orientation change events. When the device orientation changes, this function is triggered.

Function listener

Property

Type

Description

alpha

Number

The rotation angle around the Z-axis when the device's X/Y coordinates align with the Earth's X/Y coordinates. The range is [0, 2π). Counterclockwise rotation is positive.

beta

Number

The rotation angle around the X-axis when the device's Y/Z coordinates align with the Earth's Y/Z coordinates. The range is [-π, π). Positive rotation occurs when the top of the phone faces the Earth's surface or if it faces toward the user.

gamma

Number

The rotation angle around the Y-axis when the device's X/Z coordinates align with the Earth's X/Z coordinates. The range is [-π/2, π/2). Positive rotation occurs when the right side of the phone faces the Earth's surface.

Sample code

copy
var listener = function (res) {
    console.log(res.alpha);
    console.log(res.beta);
    console.log(res.gamma);
}

my.onDeviceMotionChange(listener);