Jump to content
Search Community

Page scroll stuck after Barba.js transition

Mattiabf test
Moderator Tag

Recommended Posts

Good morning,

 

I have smooth scroller active on a website, but it gets stuck after barba.js transitioning.

 

I reviewed some older topics here, but even though I found many, I wasn't able to understand how to fix it.

 

 I understood that I need to "clean" and restart scrollSmoother/Trigger after transition, but then wasn't able to do it.

 

This is my code. Could you please help?

 

barba.init({
  debug: true,
  sync: true,
  timeout: 10000,
  transitions: [{
    name: 'opacity-transition',
    once(data) {
      document.addEventListener("DOMContentLoaded", function () {
        var tl = gsap.timeline();
        tl
          .to(".transoverlay", { opacity: 0 })
          .set(".transoverlay", { display: "none" })
          .from('#masthead', { opacity: 0, y: 5 }, 4)
          .from('.fadein', { opacity: 0, y: 5 });
      });
    },

    before(data) {
      return new Promise((resolve) => {
        const timeline = gsap.timeline({ onComplete: resolve });
        timeline
          .set(".pageTitle", { display: "none" })
          .set(".transoverlay", { top: "-100vh", opacity: 1, display: "flex" })
          .to(".transoverlay", { y: "100vh", opacity: 1, duration: 0.5 })
          .to(".blslogo", { display: "block", opacity: 1, duration: 0.5 })
          .to(data.current.container, { opacity: 0 }, 0.2)
          .to(".nextPage", { display: "block", opacity: 1, duration: 0.2 })
          .to(window, { scrollTo: { y: 0 } });
      });
    },

    beforeEnter(data) {
      return new Promise((resolve) => {
        const barbaNamespace = data.next.container.getAttribute('data-barba-namespace');
        const pageTitle = document.getElementById('wipertitle');
        pageTitle.innerHTML = barbaNamespace;

        const timeline = gsap.timeline({ onComplete: resolve });
        timeline
          .set("#wipertitle", { display: "block" })
          .from("#wipertitle", { opacity: 0, y: 5, duration: 0.5 })
          .set("#wipertitle", { display: "block", onComplete: resolve }, -0.5);
      });
    },

    enter(data) {
      return new Promise((resolve) => {
        const timeline = gsap.timeline({ onComplete: resolve });
        timeline
          .to(data.next.container, { opacity: 1 });
      });
    },

    after(data) {
      return new Promise((resolve) => {
        const timeline = gsap.timeline({ onComplete: resolve });
        timeline
          .to("#wipercontent", { opacity: 0, duration: 0.5 })
          .to(".transoverlay", { y: "200vh", opacity: 0, duration: 0.5, display: "none" })
          .set("#wipercontent", { opacity: 1 })
          .set(".blslogo", { opacity: 0, display: "none" });
      });
    }
  }]
});

 

Link to comment
Share on other sites

It's pretty tough to troubleshoot without a minimal demo - the issue could be caused by CSS, markup, a third party library, your browser, an external script that's totally unrelated to GSAP, etc. Would you please provide a very simple CodePen or Stackblitz that demonstrates the issue? 

 

Please don't include your whole project. Just some colored <div> elements and the GSAP code is best. See if you can recreate the issue with as few dependancies as possible. If not, incrementally add code bit by bit until it breaks. Usually people solve their own issues during this process! If not, then at least we have a reduced test case which greatly increases your chances of getting a relevant answer.

 

Here's a starter CodePen that loads all the plugins. Just click "fork" at the bottom right and make your minimal demo

See the Pen aYYOdN by GreenSock (@GreenSock) on CodePen

 

Using a framework/library like React, Vue, Next, etc.? 

CodePen isn't always ideal for these tools, so here are some Stackblitz starter templates that you can fork and import the gsap-trial NPM package for using any of the bonus plugins: 

 

Please share the StackBlitz link directly to the file in question (where you've put the GSAP code) so we don't need to hunt through all the files. 

 

Once we see an isolated demo, we'll do our best to jump in and help with your GSAP-specific questions. 

Link to comment
Share on other sites

Hi,

 

Besides echoing the need of a minimal demo, my only suggestion would be to kill and then create the ScrollSmoother instance after the barba transition is completed, for example in the after callback.

 

Something like this:

after(data) {
  return new Promise((resolve) => {
    const timeline = gsap.timeline({ onComplete: () => {
      smoother.kill();
      smoother = ScrollSmoother.create({
        // Smoother config here
      });
      resolve();
    }});
    timeline
      .to("#wipercontent", { opacity: 0, duration: 0.5 })
      .to(".transoverlay", { y: "200vh", opacity: 0, duration: 0.5, display: "none" })
      .set("#wipercontent", { opacity: 1 })
      .set(".blslogo", { opacity: 0, display: "none" });
  });
}

You can create a minimal demo using Stackblitz's static HTML starter template:

95k2HLs.png

Hopefully this helps.

Happy Tweening!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...