您的位置:首页 > 其它

网格背景棋盘实现canvas

2018-07-04 11:03 106 查看
<!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>
阅读更多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: