Jump to content
Search Community

Simple linear gradient animation

dada78 test
Moderator Tag

Go to solution Solved by Rodrigo,

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

  • Solution

Hi,

 

I believe you're asking too much from the CSS Plugin. Parsing all that data apparently is not possible, so what you have to do is create a common JS object with a property with a starting value of 0 and then tween that property to 1. Using an onUpdate callback pass that to your element:

var testObj = {a:0};

TweenLite.to(testObj, 3, {a:1, onUpdate: updateGradient});

function updateGradient(){
  $("#demo").css("background","linear-gradient(to top,rgba(255,255,255,0) 0%, rgba(255,255,255,"+testObj.a);
}

If you want a full crossbrowser support you'll have to use all the strings in the callback. I set up an example that can save you from typing some of that code:

 

See the Pen KAuLp by rhernando (@rhernando) on CodePen

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