@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 foronce
hook, added when first load transition is triggered, removed one frame after..barba-once-active
→ active state foronce
hook, 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 foronce
hook, added one frame after transition is triggered (at the same timebarba-once
is removed) and removed when transition/animation finishes.
leave
.barba-leave
→ starting state forleave
hook, added when leave transition is triggered, removed one frame after..barba-leave-active
→ active state forleave
hook, 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 forleave
hook, added one frame after transition is triggered (at the same timebarba-leave
is removed) and removed when transition/animation finishes.
enter
.barba-enter
→ starting state forenter
hook, added when enter transition is triggered, removed one frame after next container is inserted..barba-enter-active
→ active state forenter
hook, 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 forenter
hook, added one frame after next container is inserted (at the same timebarba-enter
is 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
/enter
hook 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-active
class 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, |