<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<canvas id="canvas" width="1024" height="768"
style="border:1px solid #aaa;display:block;margin:50px auto;"></canvas>
<script type="text/javascript">
window.onload = function () {
var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");
// 设置画布大小
canvas.width = 1024;
canvas.height = 768;
context.moveTo(100, 100);
context.lineTo(500, 500);
context.lineTo(100, 500);
context.lineTo(100, 100);
// 填充图形
context.fillStyle = "transparent";
context.fill();
context.lineWidth = 5;
context.strokeStyle = "#005588";
context.stroke();
}
</script>
</body>
</html>
canvas示例
最新推荐文章于 2022-11-30 17:41:04 发布