美文网首页
html5 canvas 教程

html5 canvas 教程

作者: wyrover | 来源:发表于2017-12-14 01:24 被阅读8次

    画线

    image.png
    <html>
        <head>
            <script>
                window.onload = function(){
                    // get the canvas DOM element by its ID
                    var canvas = document.getElementById("myCanvas");
                    // declare a 2-d context using the getContext() method of the 
                    // canvas object
                    var context = canvas.getContext("2d");
                    
                    // set the line width to 10 pixels
                    context.lineWidth = 10;
                    // set the line color to blue
                    context.strokeStyle = "blue";
                    // position the drawing cursor
                    context.moveTo(50, canvas.height - 50);
                    // draw the line
                    context.lineTo(canvas.width - 50, 50);
                    // make the line visibile with the stroke color
                    context.stroke();
                };
            </script>
        </head>
        <body>
            <canvas id="myCanvas" width="600" height="250" style="border:1px solid black;">
            </canvas>
        </body>
    </html>
    
    

    相关文章

      网友评论

          本文标题:html5 canvas 教程

          本文链接:https://www.haomeiwen.com/subject/ucmtwxtx.html