@barba/css
Barba CSS is a style helper that manage you CSS classes during transitions.
It is mainly inspired by Vue.js transitions.
How it works?
This plugin adds/removes CSS classes from the data-barba="container" DOM element automatically.
To create a simple opacity transition, use the plugin in your build:
1 | import barba from '@barba/core'; |
Then customize your CSS classes like this:
1 | .barba-leave-active, |
CSS classes
During the transition process, Barba defines custom classes according to the transition hook state. If a transition name is specified, it will be used as a CSS prefix in your classes instead.
Here is the list of all default CSS classes grouped by hooks:
once
.barba-once→ starting state foroncehook, added when first load transition is triggered, removed one frame after..barba-once-active→ active state foroncehook, applied during the entire appearing phase, then added when once transition is triggered and removed when transition/animation finishes. This class can be used to define the duration, delay and easing curve..barba-once-to→ ending state foroncehook, added one frame after transition is triggered (at the same timebarba-onceis removed) and removed when transition/animation finishes.
leave
.barba-leave→ starting state forleavehook, added when leave transition is triggered, removed one frame after..barba-leave-active→ active state forleavehook, applied during the entire leaving phase, then added when leave transition is triggered and removed when transition/animation finishes. This class can be used to define the duration, delay and easing curve..barba-leave-to→ ending state forleavehook, added one frame after transition is triggered (at the same timebarba-leaveis removed) and removed when transition/animation finishes.
enter
.barba-enter→ starting state forenterhook, added when enter transition is triggered, removed one frame after next container is inserted..barba-enter-active→ active state forenterhook, applied during the entire leaving phase, then added after next container is inserted and removed when transition/animation finishes. This class can be used to define the duration, delay and easing curve..barba-enter-to→ ending state forenterhook, added one frame after next container is inserted (at the same timebarba-enteris removed) and removed when transition/animation finishes.
CSS prefix
By default, the plugin uses .barba-hook prefix to generate the .barba-hook[-state] CSS classes, but if you add a name property to your transition, it uses .name-hook[-state] CSS classes instead.
Setting a transition name like this …
1 | barba.init({ |
… will generate those CSS classes:
1 | /* transition name is used as prefix for `once` hook */ |
Be careful, you need to add an empty
once/leave/enterhook in order to let the plugin use the transition name as class prefix.This may evolve in a next release.
Transition hooks
As Barba CSS plugin overrides main once / leave / enter hooks in order to run, the code you will put inside those hooks won’t be executed. However, you can safely use every other transition hooks to run custom code with the plugin:
1 | barba.init({ |
This may evolve in a next release.
Complex transition
Browser load
If you want to play some transition on first load, use the once hook:
1 | .barba-once-active { |
Don’t forget to set the
.barba-once-activeclass in order to see the transition.
Custom rule
You can use custom transition rules to play transitions depending on the namespace or route.
1 | import barba from '@barba/core'; |
1 | .fade-leave-active, |