position text on canvas - Javascript Canvas

Javascript examples for Canvas:Text

Description

position text on canvas

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> 
      <script src="name.js"></script> 
      <meta charset="ISO-8859-1"> 
      <title>Animate my name</title> 
   </head> 
   <body> 
      <canvas id="myCanvas" width="400" height="400"></canvas> 
      <script>
$(document).ready(function(){
  var canvas = $("#myCanvas")[0];
  canvas.width = window.innerWidth;
  canvas.height = window.innerHeight;
  var width_ = canvas.width/2;
  var ctx = canvas.getContext("2d");
  ctx.beginPath();/*from w w w .  ja va2  s .c  om*/
  ctx.font = "60px Comic";
  ctx.textAlign='center';
      ctx.fillText("sanjana", width_, 100);//why with width text is not visible
      });

      </script>  
   </body>
</html>

Related Tutorials