Jump to content
Search Community

Colouring background on scroll

gregor test
Moderator Tag

Go to solution Solved by mvaneijgen,

Recommended Posts

Hi, I have a problem with colouring my background.


First the header should change its colour from blue to white, later in the page when a component scrolls in the page should become black, but on leave turn back to white. But in my case it is gets blue again. I thought using toggleActions would be the best option. but it doesn't work because the page turns blue again instead of white...
 

 

 

See the Pen JjzpKOW?editors=1010 by destroy90210 (@destroy90210) on CodePen

Link to comment
Share on other sites

  • Solution

GSAP is highly optimised, so instead of figuring out what color it should change to or from it will record all the values on page load! It thus sees that it could animate from blue (the initial color) to black. Because it are two separate tweens they don't have any interaction together, so they don't know what they are doing. 

 

This could be fixed in so many ways, but in this case a immediateRender: false, on the second tween is the easiest.

 

other ways would be to set a .fromTo() from white to black, or create a timeline with all the animations and then add labels to the timeline and tell ScrollTrigger to animate to label "white" and label "black". Hope it helps and happy tweening! 

 

See the Pen MWxQjyb?editors=0010 by mvaneijgen (@mvaneijgen) on CodePen

  • Like 1
  • Thanks 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.
×
×
  • Create New...