How to draw line with JavaScript and HTML5

1 Answer

0 votes
<!DOCTYPE html>
<html>    
    <head>
        <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
        <title>Welcome to your computer...</title>                


        <script type="text/javascript">
            function drawLine()
            {
                var canvas = document.getElementById('mycanvas');

                if (canvas.getContext)
                {
                    var ctx = canvas.getContext('2d');

                    ctx.lineWidth = 3;
                    ctx.beginPath();
                    ctx.moveTo(0,0);
                    ctx.lineTo(500,0);
                    ctx.stroke();
                }
                else
                    alert('Browser not support HTML5.');
            }
        </script>
    </head>
    <body onload="drawLine();">
        <canvas id="mycanvas"></canvas>
    </body>
</html>  


answered Jun 7, 2014 by avibootz
edited Jun 7, 2014 by avibootz

Related questions

1 answer 551 views
2 answers 401 views
401 views asked May 27, 2016 by avibootz
1 answer 373 views
373 views asked May 20, 2014 by avibootz
...