Jump to content

Search In
  • More options...
Find results that contain...
Find results in...

TimelineMax Scrollbar Progress Offset

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!



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.






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

@Sahil Thanks for your reply mate! This was my first thought, however this will only trigger once the main div (.tweener) comes into view, I would like the animations to start as each item comes into view...

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

16 hours ago, Sahil said:

The way you have created your tweener class(or is it Blake's demo? )


Doesn't look like anything I made, but I see the similarities. :-D

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