title: FadeIn FadeOut in Html5 canvas
body: <p>I ve got an canvas with an image and i want to fadein and fade out the image constantly. I ve used the above code:</p>
  
  <pre><code>&lt;!DOCTYPE HTML&gt;
   &lt;html&gt;
  &lt;head&gt;
      &lt;script&gt;
          var canvas;
          var context;
          var ga = 0.0;
          var timerId = 0;
          var timerId1 = 0;
  
          function init()
          {
              canvas = document.getElementById("myCanvas");
              context = canvas.getContext("2d");
  
              timerId = setInterval("fadeIn()", 300);
              console.log(timerId);
  
          }
  
          function fadeIn()
          {
              context.clearRect(0,0, canvas.width,canvas.height);
              context.globalAlpha = ga;
              var photo = new Image();
              photo .onload = function()
              {
                  context.drawImage(photo , 0, 0, 450, 500);
              };
              photo .src = "photo .jpg";
  
              ga = ga + 0.1;
  
              if (ga &gt; 1.0)
              {
                  fadeOut();
                  goingUp = false;
                  clearInterval(timerId);
  
              }
          }
  
          function fadeOut()
          {
              context.clearRect(0,0, canvas.width,canvas.height);
              context.globalAlpha = ga;
  
              var photo = new Image();
              photo .onload = function()
              {
                  context.drawImage(photo , 0, 0, 450, 500);
              };
              photo .src = "photo .jpg";
  
              ga = ga - 0.1;
  
              if (ga &lt; 0)
              {
  
                  goingUp = false;
                  clearInterval(timerId);
              }
          }
      &lt;/script&gt;
  &lt;/head&gt;
  &lt;body onload="init()"&gt;
      &lt;canvas height="500" width="500" id="myCanvas"&gt;&lt;/canvas&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p></p>
  
  <p>Is it possible to insert two functions into setIntervals?? I want to trigger fadeOut after fadeIn function. How is it possible??</p>