| 1 | --- |
| 2 | title: "htmx:before:viewTransition" |
| 3 | description: "Before View Transition API starts" |
| 4 | --- |
| 5 | |
| 6 | The `htmx:before:viewTransition` event fires before a View Transition starts (if browser supports View Transitions API and `htmx.config.transitions` is |
| 7 | `true`). |
| 8 | |
| 9 | ## When It Fires |
| 10 | |
| 11 | Before the swap operation begins its view transition animation. |
| 12 | |
| 13 | ## Event Detail |
| 14 | |
| 15 | - `task` - Transition callback function |
| 16 | |
| 17 | ## Example |
| 18 | |
| 19 | ```javascript |
| 20 | htmx.on('htmx:before:viewTransition', (evt) => { |
| 21 | console.log('Starting view transition'); |
| 22 | // Customize transition behavior |
| 23 | }); |
| 24 | ``` |
| 25 | |
| 26 | Cancel this event to skip the view transition for this swap. |