position text on canvas - Javascript Canvas

Javascript examples for Canvas:Text


position text on canvas

Demo Code

ResultView the demo in separate window

      <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> 
      <canvas id="myCanvas" width="400" height="400"></canvas> 
  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.fillText("sanjana", width_, 100);//why with width text is not visible


Related Tutorials