Jump to content
Search Community

ScrollTo x Horizontal ScrollTrigger with window.location.hash

VBMP test
Moderator Tag

Recommended Posts

Hi,

 

I wondered if anyone could point me in the right direction, I feel like I'm very close to having a rather complex (IMO) horizontal scrolling site working rather smoothly thanks to GSAP and the community forums. So far, I've managed to complete 99% on my own but could do with a little help to solve one final issue that has me stumped.

 

I have attached the above Codepen which provides a simple example of my current setup with the ScrollTo plugin animating the containerAnimation to the relevant section upon the anchor link click. (Located at the foot of the page.)

 

However, I would like to also be able to animate to the relevant section on page load eg: https://www.example.com/#section-2

 

I have found an example of this working in a traditional vertical scroll (see below), but could do with some help integrating the below into the simplified horizontal scroll I have attached at the foot of the page. A bonus would also be updating the window location hash on the scroll position, but happy to save this for another time.

 

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

 

Any help would be greatly appreciated. 

 

Thanks,

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

Link to comment
Share on other sites

Hi,

 

You can check for the hash in the URL after creating all the ScrollTrigger instances. If for some reason you don't get the right values, you could use a short setTimeout (about 50 ms) to be sure that you get the right values. You already have the getScrollLookup method ready for that.

 

As for updating the hash as you scroll, yeah I don't know about that, you'd have to search for that in Google, but that's beyond the scope of these forums. Is far simpler to give a specific class to the current active link.

 

Hopefully this helps.

Happy Tweening!

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