Last active
May 23, 2023 08:57
-
-
Save glafarge/293297c9bc92a5a0a138b585b70166b7 to your computer and use it in GitHub Desktop.
Barba.js / Transitions and views
This file contains hidden or 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 hidden or 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