-
-
Save mfrancois3k/fa7f751e47003cb678fdaf847c6d5b01 to your computer and use it in GitHub Desktop.
Barba.js / Transitions and views
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | |
}); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ./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