> ## Documentation Index
> Fetch the complete documentation index at: https://docs.rebellapp.com/llms.txt
> Use this file to discover all available pages before exploring further.

# my.onDeviceMotionChange

> Listen for device orientation change events.

Use this API to listen for device orientation change events. Events are delivered after `my.startDeviceMotionListening` has been called.

## Parameters

| Type | Required | Description |
| - | - | - |
| Function listener | Yes | Called when the device orientation changes |

## Listener Callback

| Property | Type | Description |
| - | - | - |
| alpha | Number | Rotation around the Z-axis when the device's X/Y axes align with the Earth's. Range `[0, 2π)`; counterclockwise is positive |
| beta | Number | Rotation around the X-axis when the device's Y/Z axes align with the Earth's. Range `[-π, π)`; positive when the top of the phone faces the Earth's surface or the user |
| gamma | Number | Rotation around the Y-axis when the device's X/Z axes align with the Earth's. Range `[-π/2, π/2)`; positive when the right side of the phone faces the Earth's surface |

## Code Example

```javascript theme={null}
Page({
  onLoad() {
    this.onMotion = (res) => {
      this.setData({ alpha: res.alpha, beta: res.beta, gamma: res.gamma });
    };
    my.startDeviceMotionListening({ interval: 'normal' });
    my.onDeviceMotionChange(this.onMotion);
  },
  onUnload() {
    my.offDeviceMotionChange(this.onMotion);
    my.stopDeviceMotionListening();
  }
});
```

## Related APIs

> [card] [my.startDeviceMotionListening](https://docs.rebellapp.com/jsapi/device/device-motion/my.startDeviceMotionListening.md)
>
> Start listening

> [card] [my.offDeviceMotionChange](https://docs.rebellapp.com/jsapi/device/device-motion/my.offDeviceMotionChange.md)
>
> Remove listeners


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.