@barba/css
Barba CSS is a style helper that manage you CSS class during transitions.
It is mainly inspired by Vue.js transitions.
Definition
This module adds/removes CSS classes from the data-barba="container"
DOM element automatically. By default, it uses .barba-xxx[-xxx]
but if you add a name
property to your transition, it uses .name-xxx[-xxx]
CSS classes instead.
Usage
During the transition process, Barba defines custom classes according to the transition appear
/ leave
/ enter
hooks and the transition name, if specified. Here is the list of hooks supported by the module:
appear
.barba-appear
: starting state forappear
, added when appear transition is triggered, removed one frame after..barba-appear-active
: active state forappear
, applied during the entire appearing phase, then added when appear transition is triggered and removed when transition/animation finishes. This class can be used to define the duration, delay and easing curve..barba-appear-to
: ending state forappear
, added one frame after transition is triggered (at the same timebarba-appear
is removed) and removed when transition/animation finishes.
leave
.barba-leave
: starting state forleave
, added when leave transition is triggered, removed one frame after..barba-leave-active
: active state forleave
, 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
, 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
, added when enter transition is triggered, removed one frame after next container is inserted..barba-enter-active
: active state forenter
, 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
, added one frame after next container is inserted (at the same timebarba-enter
is removed) and removed when transition/animation finishes.
Example with default naming:
1 | import barba from '@barba/core' |
Then customize your CSS classes like this:
1 | /* transition active state (same for leave and enter) */ |
If you want to play some transition on first load, use appear
:
1 | /* appear: active state, define the transition */ |
If you want different transitions, you can name them and use rules.
The transition name
will be used as CSS “prefix”.
1 | import barba from '@barba/core' |
1 | /* fade and slide transition active states (same for leave and enter) */ |