Jump to content
Search Community

Animating text with a gradient on scroll

Josh Rogers test
Moderator Tag

Recommended Posts

Hey guys, 

 

How would I go about creating some text that has a CSS gradient background which changes on scroll?

 

Apple have a really good example here:

https://www.apple.com/uk/iphone-12-pro/

 

There is a section which reads "Less bezel, more screen" and the text has a light to black gradient which changes on scroll

 

Any help is much appreciated :)

Link to comment
Share on other sites

I see several approaches. You could simply move or scale a transparent to black gradient over the white text. Depending on the use case you might have to work wit a mask. All this of course  handled with scroll trigger. In the case of the apple site the fact tat ist all black in black makes it easier than when you would have backgrounds you don't want to hide.  

  • Like 2
Link to comment
Share on other sites

Hey there,

 

Thanks for your reply

 

I like the sound of the the first option that you mentioned with scaling or moving a transparent to black gradient over the text

 

I don't suppose you would be able to do a codePen showcasing this in action? I am new to scrollTrigger and gsap so still learning all it's tips and tricks 

Link to comment
Share on other sites

 

Hey @Josh Rogers - welcome to the forums.

 

Pretty much the same has been asked just recently in this thread below.

 

Although there is no explicit example with ScrollTrigger intergrated, if you follow along that thread, you should be stearing into the right direction.

 

The example for the animation itself uses a gradient as a mask.

 

 

Hope this helps.

 

  • Like 3
Link to comment
Share on other sites

@Josh Rogers I might give the CodePen a spin, as I haven't real worked with scroll trigger but need to do so in an other project.
I have recently done a 'one line scroller' with a mask and came across several tricky problems. One of which was to determine the actual text-width, as I was working with web-fonts and I had to check for the event when the font was applied. Do you need to consider that?  

Link to comment
Share on other sites

In that case it might be best to use background-clip: text an animate the actual background gradient. 
shouldn’t be to hard, just a little more ‘abstract’ than sliding a gradient over white text.

I’m not sure about browser support, but I guess by now it should be quite ok. 

Link to comment
Share on other sites

this thread got me tinkering with background-clip:text (as iDad5 suggested). 

I'm going to use this for an upcoming lesson for my students in my Creative Coding Club.

 

however, if you want a sneak peek at a not-so-ready-for-production version here you go:

 

See the Pen 6720103d55791e83f754ce7a1a7dc008 by snorkltv (@snorkltv) on CodePen

 

if you're on mobile, try landscape mode.

 

the short version of how it works is that the text has a gradient that goes from black to "white" to black at a 45deg angle.

I use a gsap tween to move those colors over to the right. Each tween has a ScrollTrigger attached.

 

I'll probably find a way to turn those 2 sentences into a 15-20 min video.

  • Like 5
Link to comment
Share on other sites

  • 1 year later...

The apple site is adding a position: sticky; to the text, then achieving the gradient effect by animating a mix-blend-mode: darken; colored gradient vertically (in that same sticky container). You could do the same thing with ScrollTrigger and pinning, pretty easily.

Similar to this, but animating a gradient instead of parts of a shoe:

See the Pen gOabMXv by GreenSock (@GreenSock) on CodePen

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