且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在画布HTML5上绘制网格/表格

更新时间:2023-11-24 12:07:46

答案来自这里使用< canvas>绘制的网格元素看起来很舒服

刚刚编辑了一下,希望它有所帮助

Just edited it a little, hope it helps

<html>
<head>
<script type="text/javascript" language="javascript">
// Box width
var bw = 400;
// Box height
var bh = 400;
// Padding
var p = 10;

var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");
function drawBoard(){
for (var x = 0; x <= bw; x += 40) {
    context.moveTo(0.5 + x + p, p);
    context.lineTo(0.5 + x + p, bh + p);
}


for (var x = 0; x <= bh; x += 40) {
    context.moveTo(p, 0.5 + x + p);
    context.lineTo(bw + p, 0.5 + x + p);
}

context.strokeStyle = "black";
context.stroke();
}

drawBoard();
</script>
</head>
<body style=" background: lightblue;">
    <canvas id="canvas" width="420px" height="420px" style="background: #fff; margin:20px"></canvas>
</body>
</html>