Search the Blog

Tuesday, August 6, 2019

JavaScript Canvas uses and demo example

Canvas elements in HTML used for building rectangular based building shape-

First create a canvas element variable, Then declare the width and height

      var canvas_rectangle = document.createElement('canvas');
      canvas_rectangle .width = 500; 
      canvas_rectangle .height = 250;


Please select a context for the canvas- it may be 2D, 3D in first example we will use 2D.
     var ctx_can = canvas_rectangle .getContext('2d');

Then we have to set all property related to canvas

      ctx_can .font = '30px Cursive';
      ctx_can .fillText("www.dizsweb.com?", 50, 50);


Then finnaly we to insert  canvas element into the page to take effect of all above code:
     document.body.appendChild(canvas_rectangle);



No comments:

Post a Comment

Translate