Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GSAP cancels scrollTo animation #558

Open
EddyRespondek opened this issue May 8, 2024 · 0 comments
Open

GSAP cancels scrollTo animation #558

EddyRespondek opened this issue May 8, 2024 · 0 comments

Comments

@EddyRespondek
Copy link

EddyRespondek commented May 8, 2024

I'm having issues with the following code. If GSAP is run during scrollTo then the scroll is cancelled. I also tried using with on scroll and the issue remains. Is there a known work around for this?

const scroll = new LocomotiveScroll({
    el: document.querySelector('[data-scroll-container]'),
    smooth: false,
    multiplier: 1,
    getDirection: true,
    offset: ["15%", "85%"],
    repeat: false,
});

if (window.location.hash) {
    if ( document.querySelector('.header') ) {
		offset = parseInt('-' + ( document.querySelector('.header').offsetHeight ));
	}

    scroll.scrollTo( window.location.hash, { offset: offset } );
}

scroll.on('call', (funcs, way, obj) => {
	if ( !Array.isArray(funcs) ) {
		funcs = [funcs];
	}

	funcs.forEach((func) => {
		if ( func === 'layoutInView' ) {
			layoutInView(way, obj);
		}
	});
});

function layoutInView(way, obj) {
	const h1 = document.querySelectorAll('#' + obj.targetEl.getAttribute('id') + ' h1');

	if ( way === 'enter' ) {
		h1.forEach((title) => {
			if ( !title.classList.contains('done') ) {
				const splitTitle = new SplitType(title, { types: 'lines, chars' });

				gsap.from(splitTitle.chars, {
					opacity: 0,
					y: 0,
					duration: 1,
					stagger: { amount: 2 },
				});

				title.classList.add('done');
			}
		});
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant