<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>网格</title>
<style>
#chess {
display: block;
margin: 50px auto;
box-shadow: -2px -2px 2px #efefef , 5px 5px 5px #b9b9b9;
}
#chess:hover{
cursor: pointer;
}
</style>
<script type="text/javascript">
window.onload = function () {
var chess = document.getElementById('chess');
var context = chess.getContext('2d');
function drawtable(){
for (var i = 0; i<15; i++){
for (var j = 0; j<15 ;j++){
//绘制横线
context.moveTo(15, 15 +j *30);
context.lineTo(435, 15 +j *30);
//绘制竖线
context.moveTo(15+j*30,15);
context.lineTo(15+j*30,435);
//使用灰色描边
context.strokeStyle = "#bfbfbf";
context.stroke();
}
}
};
drawtable();
};
</script>
</head>
<body>
<canvas id="chess" width="450px" height="450px"></canvas>
</body>
</html>
网格背景棋盘实现canvas
最新推荐文章于 2024-05-08 13:42:39 发布