Jump to content
Search Community

onReverseComplete callback is not showing certain elements

dishajk test
Moderator Tag

Recommended Posts

useLayoutEffect(() => {

  const animationContext = gsap.context(() => {
    const timeline = gsap.timeline();
    const timelineButtonOff = gsap.timeline();

    timeline.to(".landingOverlay", {
      opacity: 1,
      zIndex: 1,
      duration: 0.1,
      paused: isButtonClicked,
      ease: "none"
    });
    timeline.to(marqueeDummy, {
      duration: 0.3,
      opacity: 0.4,
    });
    
    const loopDummy = horizontalLoop(marqueeDummy, {
      repeat: -1,
      speed: 0.3,
      reversed: true
    });
    const loop = horizontalLoop(marquee, {
      repeat: -1,
      speed: 0.3
    });

    timeline.add(loopDummy, 0.1);
    timeline.add(loop, 0);
    
    timelineButtonOff.to(".menuCarousel", {
      x: '-' + distance,
      ease: "none",
      scrollTrigger: {
        trigger: ".landingScreen",
        toggleActions: "restart pause reverse reset",
        start: "center 45%",
        end: "+=3000",
        scrub: 0.1,
        pin: true,
        pinSpacing: true,
      },
      onReverseComplete: () => {
        setIsButtonClicked(false);
        timeline.play();
        console.log('timeline has restarted');
      }
    });

    if (!isButtonClicked) {
      timeline.play();
    } else {
      timeline.kill();
      timelineButtonOff.play();
    }
  });

  return () => {
    animationContext.revert();
  };
}, [isButtonClicked]);
<div className='landingOverlay position-absolute' onWheel={handleButtonClick}>

{/* landingOverlay content */}
      <button className='d-block rippleButton' onClick={handleButtonClick}><FaAngleDown /></button>
</div>
<div ref={landingScreenRef} className="landingScreen">
  <div className={`marquee position-relative ${isButtonClicked ? '' : 'rotatedContainer'}`}>
    <div className="dummyCarousel d-flex flex-row">
      {/* dummyCarousel content */}
    </div>
    <div className='my-4'>
      <div className='d-flex flex-row menuCarousel position-relative'>
        {/* menuCarousel content */}
      </div>
    </div>
    <div className='dummyCarousel d-flex flex-row'>
      {/* dummyCarousel content */}
    </div>
  </div>
</div>

I am trying to implement a marquee-like animation effect for a menu carousel on the landing screen. The isButtonClicked state changes from false to true when you do handleButtonClick and to false when you reverseCallback. When I reverseCallBack, the state of menuCarousel changes to original but not that of dummyCarousel. What am I doing wrong?

Edit 1: I figured that the problem is in using reversed: true for the handleLoop function

Edited by dishajk
I found more details
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 CodeSandbox that demonstrates the issue? 

 

Please don't include your whole project. Just some colored <div> elements and the GSAP code is best (avoid frameworks if possible). 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

 

If you're using something like React/Next/Vue/Nuxt or some other framework, you may find StackBlitz easier to use. We have a series of collections with different templates for you to get started on these different frameworks: React/Next/Vue/Nuxt.

 

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

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...