Jump to content
Search Community

TimelineMax Scrollbar Progress Offset

Splurtcake test
Moderator Tag

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

Hi All,

 

Hoping someone can help with this issue I'm facing.

 

I am controlling the TimelineMax progress based on scroll position. Pretty simple, however I noticed that my tweens are running for the entire length of the page. This is because I am currently calculating the percentage with age-old `window.scrollY / (document.body.clientHeight - window.innerHeight)`

 

What I need help with, is figuring out how to start & finish the animation when the `.tweener` div in my Codepen example enters the viewport, to when it reaches the bottom of the viewport.

 

I also don't want to use the behemoth that is ScrollMagic ;)

 

Any help would be greatly appreciated!

 

Cheers

See the Pen odoXwj by oculusriff (@oculusriff) on CodePen

Link to comment
Share on other sites

You can do that by only start animating once scrollY is greater than element's offset. Then use window.innerHeight to set progress. You can use innerHeight to set the percentage, the way scrollMagic trigger works.

 

https://www.kirupa.com/html5/get_element_position_using_javascript.htm

 

https://stackoverflow.com/questions/19618545/body-scrolltop-vs-documentelement-scrolltop-vs-window-pageyoffset-vs-window-scro

 

See the Pen PeObOj?editors=0010 by Sahil89 (@Sahil89) on CodePen

 

You can improve performance by avoiding calculating offset every time you scroll by saving it as Skroller property and calculating it on resize.

  • Like 4
Link to comment
Share on other sites

The way you have created your tweener class(or is it Blake's demo? ), it takes one container as trigger element and runs the animation on all items that you pass. If you want to trigger animation independently then you will need to create multiple instances of Tweener and add items to them.

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