Canvas gradients present a challenge when it comes to animating them, unlike CSS animations which are simpler. Each time the gradient changes, you need to reconstruct the gradient command.
I have created a demonstration that can help with this issue, but it requires the latest NEXT version of TweenJS, which includes a useful ColorPlugin for animating color stops.
http://jsfiddle.net/lannymcnie/uhqake7e/
UPDATE: A more straightforward approach http://jsfiddle.net/uhqake7e/2/
The essential components:
var colors = ["#ff0000", "#0000ff"],
ratios = [0,1],
w = 120, h = 120, // Shape dimensions
x0 = 0, y0 = 0, x1 = 0, y1 = h; // Gradient dimensions
// Create shape
var shape = new createjs.Shape()
.set({color1: colors[0], color2: colors[1]}); // Set initial color values
// Fill the shape and keep the command for future use
var fillCommand = shape.graphics.beginLinearGradientFill(colors, ratios, x0, y0, x1, y1).command;
To learn more about commands, refer to this article.
Next, we can animate the color values:
var tween = createjs.Tween.get(shape, {bounce:true, loop:true})
.to({color1:"#00ff00", color2:"#ff00ff"}, 1000);
Finally, update the gradient on change:
[UPDATED: Simplified approach]
tween.on("change", function(event) {
fillCommand.linearGradient([shape.color1, shape.color2], ratios, x0, y0, x1, y1);
}
An alternative method would involve using the color tween and redrawing the shape's contents, although storing all instructions would be necessary. This example updates the actual command used for the Gradient.
It is unfortunate that this process is somewhat complex compared to CSS simplicity :)
Cheers.