Jump to content


Animate background gradient on scroll

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 Guys,

I have 4 fullscreen sections on a page (using fullpage.js). I'm trying to animate the background gradient of the body every time users scroll through each section. Animation duration should be tied to the scrollbar position. I have pre-set colors to use for each section that I have put into an array. 


My idea is to get the id of the section currently in view and pass this into the colorize function to get the corresponding colors for the gradient. I'm stuck here. 


Thanks in advance

See the Pen QVeQvP by Jp_uk (@Jp_uk) on CodePen

Link to comment
Share on other sites

Hi @jp_uk81 :)


Welcome to the forum and thanks for being a member of Club GreenSock.


Since you want the gradient based on user scroll, I think in this case it will be better to create a second scene that animates only the gradient. Then you can focus on each section animation and whatever happens on those timelines without worrying about adding the gradient tween to them. I think something like this should work.



See the Pen RYXJKx by PointC (@PointC) on CodePen

If you were using the actual tween duration for the gradient change, then I'd say trigger it at each section. Hopefully that helps. Or at least points you in the right direction.


Happy tweening and welcome aboard.


  • Like 4
Link to comment
Share on other sites

It makes so much sense now. Thank you PointC! 

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