HTML5 Canvas & z-index issue - Javascript Canvas

Javascript examples for Canvas:Example

Description

HTML5 Canvas & z-index issue

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>Fixed canvas paint test</title> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" src="https://code.jquery.com/jquery-1.8.3.js"></script> 
      <style id="compiled-css" type="text/css">

#fixedContainter{position: fixed; z-index: -10; }
#otherContent{background-color:rgba(255,128,0,.9); width:50px;}
h1{position: fixed; background-color: rgba(255,255,255,.5); left:35px;}
body{height: 2000px; }
canvas{ position: fixed; z-index: -10; }


      </style> 
      <script type="text/javascript">
    $(window).load(function(){/*from w  w  w  . j  a  va2 s. c om*/
(function() {
    var c = document.getElementById("backgroundCanvas");
    var ctx = c.getContext("2d");
    ctx.beginPath();
    ctx.moveTo(0, 100);
    ctx.lineTo(0, 0);
    ctx.lineTo(100, 0);
    ctx.lineTo(1000, 1000);
    ctx.fillStyle = "rgb(117, 164, 68)";
    ctx.fill();
    ctx.closePath();
})();
    });

      </script> 
   </head> 
   <body> 
      <div id="fixedContainter"> 
         <h1>Test Title</h1> 
         <canvas id="backgroundCanvas" width="956" height="256"></canvas> 
      </div> 
      <div id="otherContent">
          line 01
         <br>
          line 02
         <br>
          line 03
         <br>
          line 04
         <br>
          line 05
         <br>
          line 06
         <br>
          line 07
         <br>
          line 08
         <br>
          line 09
         <br>
          line 10
         <br>
          line 11
         <br>
          line 12
         <br>
          line 13
         <br>
          line 14
         <br>
          line 15
         <br>
          Line outside 
      </div>  
   </body>
</html>

Related Tutorials