MennoPP's post in How do I 'reset' ScrollSmoother? was marked as the answer
June 6, 2022
Thank you all after some tries I have finally fixed it. This code works for me using GSAP + ScrollTrigger + ScrollSmoother + BarbaJS + AlpineJS
import Alpine from 'alpinejs'
window.Alpine = Alpine
Alpine.start()
import barba from "@barba/core";
import { gsap } from "gsap";
import { ScrollTrigger } from "gsap/ScrollTrigger";
import { ScrollSmoother } from "gsap/ScrollSmoother";
gsap.registerPlugin( ScrollTrigger, ScrollSmoother);
function contentAnimation () {
gsap.set(".animated_ul_title", {
opacity:0,
x:-20
});
gsap.to(".animated_ul_title", {
duration:.4,
delay:0,
opacity:1,
x:0,
scrollTrigger: {
trigger: ".animated_ul",
start: "top bottom-=400px",
}
});
}
function scrollSmootherCreate(){
ScrollSmoother.create({
smooth: 1,
effects: true,
ignoreMobileResize: true,
normalizeScroll: true
});
ScrollTrigger.refresh();
};
function galleryScroller(){
const galleryWrapper = document.querySelector('.gallery-wrapper')
const gallery = document.querySelector('.gallery')
const tl = gsap.timeline()
tl.to(gallery, {
x: `-${gallery.offsetWidth}`,
scrollTrigger: {
trigger: galleryWrapper,
start: 'top top',
end: `+=${gallery.offsetWidth}`,
pin: true,
scrub: 0.5,
}
})
}
function init(){
// do something before the transition starts
barba.hooks.before(() => {
});
// do something after the transition finishes
barba.hooks.after(() => {
ga('set', 'page', window.location.pathname);
ga('send', 'pageview');
});
// scroll to the top of the page
barba.hooks.enter(() => {
window.scrollTo(0, 0);
});
barba.init({
transitions: [
{
name: 'index',
once() {
siteFirstLoad();
scrollSmootherCreate();
galleryScroller();
contentAnimation();
},
async leave(data) {
gsap.to(data.current.container, {
opacity: 0,
});
},
async afterLeave() {
let triggers = ScrollTrigger.getAll();
triggers.forEach(function (trigger) {
trigger.kill();
});
},
async enter(data) {
gsap.from(data.next.container, {
opacity: 0,
});
},
async after() {
scrollSmootherCreate();
galleryScroller();
contentAnimation();
},
to: {
namespace: [
'index'
]
},
},
{
name: 'default',
once() {
contentAnimation();
},
async leave(data) {
gsap.to(data.current.container, {
opacity: 0,
});
},
async afterLeave() {
let triggers = ScrollTrigger.getAll();
triggers.forEach(function (trigger) {
trigger.kill();
});
},
async enter(data) {
gsap.from(data.next.container, {
opacity: 0,
});
},
async after() {
scrollSmootherCreate();
contentAnimation();
}
}
]
})
}
window.addEventListener('DOMContentLoaded', function () {
init();
});