Parameters
Success Callback Parameters
Code Example
Basic Usage
Adaptive Layout
Orientation Values
Related APIs
my.setScreenOrientation
Set screen orientation
my.onScreenOrientationChange
Listen for orientation changes
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Get the current screen orientation.
| Property | Type | Required | Description |
|---|---|---|---|
| success | Function | No | Callback on success |
| fail | Function | No | Callback on failure |
| complete | Function | No | Callback that always executes |
| Property | Type | Description |
|---|---|---|
| success | Boolean | Specifies whether the call is successful. When the value is true, the call is successful. |
| orientation | String | Indicates the orientation of the screen, portrait or landscape. |
my.getScreenOrientation({
success(res) {
console.log('Current orientation:', res.orientation);
}
});
Page({
data: {
isLandscape: false
},
onLoad() {
this.checkOrientation();
my.onScreenOrientationChange(this.handleOrientationChange);
},
checkOrientation() {
my.getScreenOrientation({
success: (res) => {
const isLandscape = res.orientation.includes('landscape');
this.setData({ isLandscape });
}
});
},
handleOrientationChange(res) {
const isLandscape = res.orientation.includes('landscape');
this.setData({ isLandscape });
},
onUnload() {
my.offScreenOrientationChange(this.handleOrientationChange);
}
});
| Value | Description |
|---|---|
portrait | Device held upright |
landscape | Device held sideways |