Jump to content
Search Community

ScrollTrigger Horizontal Scroll

pedromeneses97 test
Moderator Tag

Go to solution Solved by OSUblake,

Recommended Posts

Hello!
I've started recently using gsap and got really interest in the ScrollTrigger plugin. I'm trying to achieve something like this:
https://clorova.com/works
A horizontal scroll that has no overflow and does not shift layout, i do not care about the parallax effect. I need a heading and description always fixed on top of the slider. It only stays if i position absolute/fixed but i do not want to have to media querie from 2000px to a mobile.

How can i achieve this? Thanks.
639217800_Capturadeecra2022-03-23as16_28_15.png.1935045970a0417c2085ca50aaddc6f8.png

See the Pen oNpYyQN by pedromeneses97 (@pedromeneses97) on CodePen

Link to comment
Share on other sites

16 hours ago, OSUblake said:

Welcome to the forums @pedromeneses97

 

You just need to pin the section that wraps your text and the container, instead of pinning the container.

I have 8 elements on the horizontal scroll that are 500px each and have a margin right of 40px.

The pinned section has a margin-left of 120 and a padding of 80.
The last element on the horizontal scroll is cutted in half , is there a way to fix it? 
I fixed it creating a invisible element of 200px (margin + padding) and it worked but it's not a good fix

 

gsap.registerPlugin(ScrollTrigger)
 
let container = document.getElementById("container");
let section = document.getElementById("ContainerInformacao");
 
gsap.to(container, {
x: () => -(section.scrollWidth - document.documentElement.clientWidth),
ease: "none",
scrollTrigger: {
trigger: section,
pin: true,
scrub: 1,
 
// end: () => "+=" + container.scrollWidth ,
invalidateOnRefresh: true,
end: () => `+=${container.offsetWidth}` // will be updated
}
})


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