Run custom code

Most time, you need to run custom code on your website in order to refresh a component, reset a library or anything else according to the user navigation.

Where?

Barba Views is the best place to run custom code.
They are conditioned by a unique page namespace.

1
2
3
4
5
6
7
8
9
10
11
12
13
barba.init({
views: [{
namespace: 'home',
beforeEnter() {
// update the menu based on user navigation
menu.update();
},
afterEnter() {
// refresh the parallax based on new page content
parallax.refresh();
}
}]
});

In order to split the animation part from the standard code, we discourage you to run custom code inside Transitions as they are not designed for this.