Jump to content


FadeIn particles in HTML5 canvas

Recommended Posts

Hello everyone,


Im trying to generate particles in HTML5 canvas and then fade them in or out with random delay and animation duration time. Ultimately creating the effect of stars appears in the sky. So far i've been able to generate the particles with rgba() colour but was unable to animate the alpha value.

In the Codepen provided if you change line 18 from 

  _this.alpha = 0;


  _this.alpha = 1;

you will see that the particles are actually being drawn on the canvas.


Im not sure if i can modify directly an rgba value of a canvas shape with TweenMax or i need another approach. My animate function looks like that:

function animate(){
  for(var i = 0; i < bubbles.length; i++){
    var current = bubbles[i];
    var newAlpha = i * 0.1 % 1; //
    TweenMax.to(current, 1, {
      color: 'rgba('+ current.color + ', '+ newAlpha +')',
      delay: 0.5,
      onComplete: function(){

and i have the loop function to redraw the canvas on every frame:

function loop(){
  for (var i = 0; i < bubbles.length; i++) {

Im not sure if im doing the requestAnimationPart properly as well.




Any advice will be much appreciated!


See the Pen mJBBvE by MomchilGorchev (@MomchilGorchev) on CodePen

Link to comment
Share on other sites

Hi Diaco,


thanks for pointing me the right direction. I manage to made it work using the ColorPropsPlugin. I had a wrong function stack as well :) It needs some cleaning and some tweeks but i have what i was trying to achieve!

Big thanks for the great support!

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.