> ## 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.setScreenOrientation

> Set the screen orientation.

Use this API to lock the screen to a specific orientation. This is useful for video players, games, or other content that requires a specific orientation.

## Parameters

| Property    | Type     | Required | Description                                                         |
| ----------- | -------- | -------- | ------------------------------------------------------------------- |
| orientation | String   | Yes      | Indicates the orientation of the screen, `portrait` or `landscape`. |
| success     | Function | No       | Callback on success                                                 |
| fail        | Function | No       | Callback on failure                                                 |
| complete    | Function | No       | Callback that always executes                                       |

## Success Callback Parameters

| Property | Type    | Description                                                                                 |
| -------- | ------- | ------------------------------------------------------------------------------------------- |
| success  | Boolean | Specifies whether the call is successful. When the value is `true`, the call is successful. |

## Code Example

### Basic Usage

```javascript theme={null}
my.setScreenOrientation({
  orientation: 'landscape',
  success() {
    console.log('Orientation set to landscape');
  }
});
```

### Video Player Full Screen

```javascript theme={null}
Page({
  enterFullscreen() {
    my.setScreenOrientation({
      orientation: 'landscape',
      success: () => {
        this.setData({ isFullscreen: true });
      }
    });
  },

  exitFullscreen() {
    my.setScreenOrientation({
      orientation: 'portrait',
      success: () => {
        this.setData({ isFullscreen: false });
      }
    });
  },

  onUnload() {
    // Restore portrait when leaving the page
    my.setScreenOrientation({ orientation: 'portrait' });
  }
});
```

### Game Orientation Lock

```javascript theme={null}
Page({
  onLoad() {
    // Lock to landscape for game
    my.setScreenOrientation({
      orientation: 'landscape'
    });
  },

  onUnload() {
    // Restore portrait when leaving
    my.setScreenOrientation({
      orientation: 'portrait'
    });
  }
});
```

## Orientation Options

| Value       | Description                         |
| ----------- | ----------------------------------- |
| `portrait`  | Lock to portrait (vertical) mode    |
| `landscape` | Lock to landscape (horizontal) mode |

<Warning>
  Always reset orientation to `portrait` when leaving a page that locked the orientation, otherwise users may be stuck in an unexpected orientation.
</Warning>

## Related APIs

<CardGroup cols={2}>
  <Card title="my.getScreenOrientation" icon="mobile" href="/jsapi/device/screen-orientation/my.getScreenOrientation">
    Get current orientation
  </Card>

  <Card title="my.onScreenOrientationChange" icon="rotate" href="/jsapi/device/screen-orientation/my.onScreenOrientationChange">
    Listen for changes
  </Card>
</CardGroup>
