Jump to content
Search Community

Mobile problem with horizontal scroll

allen1997831 test
Moderator Tag

Go to solution Solved by Rodrigo,

Recommended Posts

Hello i have a problem with mobile scroll trigger problem, I want to change background as you move to next content section, the content is scroll in horizontal way on mobile.

 

Problem: I see there are 2 triggers point on my first content then messed up the color change points...the other contents seems trigger fine just first content has the problem.

 

can anyone advice me please? the point is change background color when you scroll different content section

 

thank you in advance! :) 

See the Pen zYQEayO by Dep-it-esedigital (@Dep-it-esedigital) on CodePen

Link to comment
Share on other sites

  • Solution

Hi @allen1997831 and welcome to the GSAP Forums!

 

The main issue is this:

window.addEventListener('resize', () => {
  ScrollTrigger.refresh();
  setupScrollTriggers();
});

First, there is no need to call the refresh() method on window resize, ScrollTrigger senses that by itself and debounces the refresh method to prevent wasting resources. Then you're setting up your ScrollTrigger and GSAP instances on every resize event without killing and reverting them, hence the extra markers you're seeing, because you have multiple ScrollTrigger instances that are starting at the same time, one for every resize callback.

 

For this is far better to just use GSAP MatchMedia:

https://gsap.com/docs/v3/GSAP/gsap.matchMedia()

 

Here is a fork of your demo:

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

 

Hopefully this helps.

Happy Tweening!

Link to comment
Share on other sites

8 hours ago, Rodrigo said:

Hi @allen1997831 and welcome to the GSAP Forums!

 

The main issue is this:

window.addEventListener('resize', () => {
  ScrollTrigger.refresh();
  setupScrollTriggers();
});

First, there is no need to call the refresh() method on window resize, ScrollTrigger senses that by itself and debounces the refresh method to prevent wasting resources. Then you're setting up your ScrollTrigger and GSAP instances on every resize event without killing and reverting them, hence the extra markers you're seeing, because you have multiple ScrollTrigger instances that are starting at the same time, one for every resize callback.

 

For this is far better to just use GSAP MatchMedia:

https://gsap.com/docs/v3/GSAP/gsap.matchMedia()

 

Here is a fork of your demo:

 

 

 

Hopefully this helps.

Happy Tweening!

Thank you so much for your time! this community is amazing.

  • Thanks 1
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...