在下面给出的示例中,我们首先定义了网格的宽度和高度。然后我们定义了画布的大小,并将网格绘制到画布上。
//we are setting the grid width and height var grid_w = 200; var grid_h = 200; //we are setting padding around grid var gridp = 15; //we are defining size of canvas by defining its width and height var canvas_w = grid_w + (gridP*2) + 1; var canvas_h = grid_h + (gridP*2) + 1; var canvas = $('<canvas/>').attr({width: canvas_w, height: canvas_h}).appendTo('body'); var ctx = canvas.get(0).getContext("2d");
这是我们的方法 −
function drawBoard(){ for (var a = 0; a <= grid_w; a += 50) { ctx.moveto(0.5 + a + gridp, gridp); ctx.lineto(0.5 + a+ gridp, grid_h + gridp); }
以上就是如何使用HTML5和canvas或SVG绘制网格?的详细内容,更多请关注编程之家其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。