1 Star 0 Fork 0

CoprizePiyo/canvas

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
test.html 1.36 KB
一键复制 编辑 原始数据 按行查看 历史
CoprizePiyo 提交于 2017-07-30 09:17 . 111
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style type="text/css">
html,body{
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<canvas id="canvas" style="display:block; border: 1px solid #ccc; margin:50px auto;">
当前浏览器不支持绘图,请更换浏览器
</canvas>
<script>
window.onload = () => {
const canvas = document.getElementById('canvas');
canvas.width = 1000;
canvas.height = 500;
if (canvas.getContext('2d')) {
const context = canvas.getContext('2d');
context.beginPath();
context.moveTo(100, 100);
context.lineTo(450, 450);
context.lineTo(100, 450);
context.lineTo(100, 100);
context.closePath();
context.fillStyle = "yellow";
context.fill();
context.lineWidth = 5;
context.strokeStyle = "purple";
context.stroke();
context.beginPath();
context.moveTo(150, 100);
context.lineTo(500, 450);
context.closePath();
context.lineWidth = 5;
context.strokeStyle = "red";
context.stroke();
} else {
alert('当前浏览器不支持绘图,请更换浏览器');
}
}
</script>
</body>
</html>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/piyo/canvas.git
[email protected]:piyo/canvas.git
piyo
canvas
canvas
master

搜索帮助