---
name: "onWindowResize"
mode: "api"
versionRequirements:
  - { name: "Base Library", version: "2.6.0" }
title: "ty.onWindowResize - Supported from base library 2.6.0, compatibility handling required for earlier versions"
---

## onWindowResize

> [VERSION] Base Library >= 2.6.0

### Description

Listen for window resize events

### Parameters

`(callback: Function)`

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `callback` | `(res: OnWindowResizeCallbackResult) => void` | Yes | Callback for window resize events |

### Return Value

None


### Referenced Types

##### `interface` OnWindowResizeCallbackResult

| Property | Type | Description |
| --- | --- | --- |
| `type` | `"portrait" \| "landscape"` | Change type |
| `size` | `OnWindowResizeCallbackResultSize` | Updated window size |

##### `interface` OnWindowResizeCallbackResultSize

| Property | Type | Description |
| --- | --- | --- |
| `windowWidth` | `number` | Screen width in px |
| `windowHeight` | `number` | Screen height in px |


### Examples

#### Listen for window size changes

```js
Page({
  onLoad() {
    ty.onWindowResize((res) => {
      console.log('Direction', res.type);
      console.log('Width', res.size.windowWidth);
      console.log('Height', res.size.windowHeight);
    });
  },
});
```
