Skip to content

Instantly share code, notes, and snippets.

@mfrancois3k
Forked from glafarge/app.js
Created May 23, 2023 08:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mfrancois3k/fa7f751e47003cb678fdaf847c6d5b01 to your computer and use it in GitHub Desktop.
Save mfrancois3k/fa7f751e47003cb678fdaf847c6d5b01 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