I accomplished to fade a line with this code
function fadeOut(ctx, canvas) {
ctx.fillStyle = "rgba(255,255,255,0.1)";
ctx.fillRect(0, 0, canvas.width, canvas.height);
setTimeout(() => fadeOut(ctx, canvas), 50);
}
But the problem with this type of fading is, it fills the transparent background with a color and this cause the background div to fade as well.
The type of fading I would like to achieve is on gartic.io's background canvas.
You can check gartic.io