Hi,
I have a site using barba.js that has a footer menu. I'm using a simple GSAP Tween to fade the pages in and out which works OK, but if you use the footer menu links, when the next page is transitioned in you always start at the bottom of the page (footer) instead of the top?
I can't work out what the problem is 鈥斅燽asic HTML and full JS below. Any help would be awesome.
The basic page HTML is
<body data-barba="wrapper">
<div class="wrapper" data-barba="container">
<header>
// menu links
</header>
// content
<footer>
// menu links
</footer>
</div>
</body>
JAVASCRIPT
var animationEnter = (container) => {
return gsap.from(container, {autoAlpha: 0, duration: 1.2, ease:'none', clearProps: 'all', ease: 'power1.inOut'})
}
var animationLeave = (container, done) => {
return gsap.to(container, {autoAlpha: 0, duration: .7, ease:'none', clearProps: 'all', ease: 'power1.inOut', onComplete: () => done()})
}
barba.init({
transitions: [
{
once({next}){
animationEnter(next.container)
},
leave({current}){
console.log('leaving')
var done = this.async();
animationLeave(current.container, done)
},
enter({next}){
console.log('entering')
animationEnter(next.container)
},
}
]
})
You can use the global hook to scroll to the top of the new page before it shows.
barba.hooks.enter(() => {
window.scrollTo(0, 0);
});
Check out this GitHub repo. The GSAP demos is using it.
Thanks Petr.
Also a huge thank you for your Barba course. It's been so helpful.
Duplicate of #537.
Most helpful comment
You can use the global hook to scroll to the top of the new page before it shows.
barba.hooks.enter(() => { window.scrollTo(0, 0); });Check out this GitHub repo. The GSAP demos is using it.