Jump to content
Search Community

gsap.to() and ScrollTrigger - How to go next and prev on Horizontal scroll

Joruus test
Moderator Tag

Recommended Posts

Hi!

 

I have an horizontal scroll with several slides with gsap.to and ScrollTrigger. When the scroll reaches a new slide, it changes the text. This works great. 

There are also previous and next buttons. I need those buttons to scroll to the previous or next slide (obvious :P ). I've tried with seek() and other ways, but i don't know how to achieve it. How can i make it work?

 

I've made a codepen: 

 

Thanks in advance ;)

See the Pen JjWzPqe by joruus (@joruus) on CodePen

Link to comment
Share on other sites

  • Joruus changed the title to gsap.to() and ScrollTrigger - How to go next and prev on Horizontal scroll

Hey @Joruus,

Welcome to the forums! 🥳

The scrollTo plugin will be what you're after - I've added some dummy code, you'll need to calculate the width of your sections and scroll by the correct measurements - but this should set you in the right direction.

 

See the Pen abf4e4299dc344a3d5cd2d1945e00f61?editors=1011 by cassie-codes (@cassie-codes) on CodePen

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