### Use async/await in visit:start handler
Source: https://github.com/swup/docs/blob/main/src/docs/lifecycle/hooks.md
Async/await handlers are supported. This example waits for a custom function before starting the transition.
```javascript
// Wait for a custom function before starting the transition
swup.hooks.on('visit:start', async () => {
await myCustomFunction();
});
```
--------------------------------
### Complete example: full HTML setup
Source: https://github.com/swup/docs/blob/main/src/docs/getting-started/example.md
The complete code required for a basic Swup setup, combining the content container, animation styles, and initialization in a single HTML file.
```html
Welcome
Lorem ipsum dolor sit amet.
```
--------------------------------
### Install locally: clone repository and install dependencies
Source: https://github.com/swup/docs/blob/main/README.md
Clones the swup/docs repository and installs npm dependencies. Run these commands in a terminal to set up the project locally.
```sh
git clone git@github.com:swup/docs.git
cd ./docs
npm install
```
--------------------------------
### Install a delegated event listener with delegateEvent
Source: https://github.com/swup/docs/blob/main/src/docs/api/helpers.md
Install a delegated event listener on the document using delegate-it. The example listens for submit events on form elements.
```javascript
const delegation = delegateEvent('form', 'submit', (event) => {
console.log('Form submitted');
});
```
--------------------------------
### HTML example with from-* and to-* classes
Source: https://github.com/swup/docs/blob/main/src/docs/getting-started/upgrading-v3.md
Example HTML output when the Route Name Plugin is configured with `paths: true`, showing `from-homepage` and `to-about` classes.
```html
```
--------------------------------
### Install @swup/scroll-plugin via npm
Source: https://github.com/swup/docs/blob/main/src/docs/plugins/plugins.md
Install the scroll plugin package using npm.
```shell
npm install @swup/scroll-plugin
```
--------------------------------
### Install Swup via npm
Source: https://github.com/swup/docs/blob/main/src/docs/getting-started/installation.md
Use this command to install the Swup package in projects using a bundler.
```shell
npm install swup
```
--------------------------------
### Interactive demo link
Source: https://github.com/swup/docs/blob/main/src/docs/getting-started/example.md
An interactive demo to try out the fade animation built in this guide. The demo is hosted at the provided URL.
```swupdemo
https://swup-demos.onrender.com/basic/
Swup Demo: Basic
```
--------------------------------
### Delay page transition with a promise in visit:start
Source: https://github.com/swup/docs/blob/main/src/docs/lifecycle/hooks.md
Return a promise from a hook handler to pause execution. This example delays the start of the page transition by 1 second.
```javascript
// Delay the start of the page transition by 1 second
swup.hooks.on('visit:start', () => {
return new Promise((res) => setTimeout(res, 1000));
});
```
--------------------------------
### Set all hook handlers at once in Swup instance options
Source: https://github.com/swup/docs/blob/main/src/docs/lifecycle/hooks.md
When creating a Swup instance, you can register multiple hook handlers by passing a keyed object to the 'hooks' option. This example registers handlers for 'visit:start', 'page:load', and 'visit:end'.
```javascript
const swup = new Swup({
hooks: {
'visit:start': () => console.log('starting visit'),
'page:load': () => console.log('loaded page'),
'visit:end': () => console.log('finished visit')
}
})
```
--------------------------------
### Example visit object shape
Source: https://github.com/swup/docs/blob/main/src/docs/lifecycle/visit.md
Example visit object for a navigation from /home to /about#anchor. Shows the shape and properties of the visit object, including from, to, containers, animation, trigger, cache, history, scroll, and meta.
```javascript
{
id: 1042739, /* A unique ID to identify this visit */
from: {
url: '/home',
hash: ''
},
to: {
url: '/about',
hash: '#anchor',
html: undefined, /* The HTML string of /about, when it's loaded */,
document: undefined /* The parsed document of /about, when it's loaded */,
},
containers: [
'#swup'
],
animation: {
animate: true,
name: 'fade'
},
trigger: {
el: /*