Jump to content
Search Community

Can GSAP animation be tied to scroll?

jpyne4 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

Sorry if this is a noob questions, but I'm a noob to GreenSock -- can someone point me to the documentation if I can tie an animation to scroll?  ie -- I want an image to scale and become opaque as I'm scrolling down the site to reveal some content behind it.  If they stop scrolling mid animation, I would like it to stop animating.  Thanks in advance.

Link to comment
Share on other sites

Absolutely. Just pause the initial timeline and use the user's calculated scroll position (scroll distance/container height) to get a number from 0 to 1 and continually use that update value to set the timeline's progress() value.

 

If you're already using jQuery, something like this

var tl = new TimelineLite( {paused: true} );

$(window).scroll( function(){
  var st = $(this).scrollTop();
  var ht = $( '#some-container' ).height();
   if( st < ht && st > 0 ){
        windowScroll = st/ht;
        tl.progress( windowScroll );
    }
});

 

Of course with some actual animations happening on the timeline :)

  • Like 5
Link to comment
Share on other sites

  • 2 years later...
On 10/5/2017 at 12:47 AM, Shaun Gorneau said:

I just updated my first comment .. should help. Stick with it ... GSAP is awesome!

Shaun thank you so so much. with GSAP3 it is was really confusing to work with scroll magic so I was searching for another option. but now I can accomplish all the animations without scrollMagic and just by using GSAP3. thank you :)

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