Draw canvas line - Javascript Canvas

Javascript examples for Canvas:Line

Description

Draw canvas line

Demo Code

ResultView the demo in separate window

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

canvas{// w  w w  .ja  va 2s .c o  m
   border:1px solid red;
   height: 720px;
   width: 1280px;
   clear:none;
}
      </style> 
      <script type="text/javascript">
    $(window).load(function(){
function lines(xo, yo)
{
   var xl, xline, yl, yline, Dx, Dy, a, b, c, d, e;
   xo=xo;
   yo=yo;
   a={top:10, left: 10};//$("#fr").position();
   b=50;//$("#fr").width();
   c=50;
   Dy=a.top+100;
   Dx=a.left;
   d=Dx+b;
   e=Dy+c;
   canvas = document.getElementById("line");
   ctx=canvas.getContext("2d");
   ctx.beginPath();
   ctx.strokeStyle = 'black';
   ctx.moveTo(Dx,yo);
   ctx.lineTo(d,yo);
   ctx.lineWidth = 15;
   ctx.stroke();
   ctx.beginPath();
   ctx.strokeStyle = 'black';
   ctx.moveTo(xo,Dy);
   ctx.lineTo(xo,e);
   ctx.lineWidth = 15;
   ctx.stroke();
}
var canvas = document.getElementById("line");
canvas.width = 1280;
canvas.height = 720;
lines(200,200);
    });

      </script> 
   </head> 
   <body> 
      <canvas id="line"></canvas>  
   </body>
</html>

Related Tutorials