Skip to content

Instantly share code, notes, and snippets.

@glafarge
Last active May 23, 2023 08:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save glafarge/293297c9bc92a5a0a138b585b70166b7 to your computer and use it in GitHub Desktop.
Save glafarge/293297c9bc92a5a0a138b585b70166b7 to your computer and use it in GitHub Desktop.
Barba.js / Transitions and views
const barba = require('@barba/core');
const anime = require('animejs');
const Home = require('./views/home');
const WhoWeAre = require('./views/whoweare');
class App {
init() {
barba.init({
transitions: [{
name: 'fade-transition',
from: 'home',
to: {
namespace: ['who-we-are']
},
leave: ({current}) => {
const animation = anime.timeline({
targets: current.container.querySelector('.m-hero__title'),
duration: 1000,
translateX: '-100%',
})
.add({
targets: current.container.querySelector('.m-hero'),
duration: 500,
opacity: [1, 0],
})
.add({
targets: current.container,
opacity: [1, 0]
});
return animation.finished;
}
}],
views: [Home, WhoWeAre]
});
}
}
// ./views/home.js
class Home {
constructor() {
this.namespace = 'home';
}
beforeEnter(data) {
// Init things
}
beforeLeave(data) {
// Destroy things
}
}
module.exports = new Home();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment