如何在 HTML 中使用脚本制作图形?
htmlweb developmentfront end technology更新于 2024/7/31 13:32:17
要使用脚本制作图形,请使用 <canvas> 标签。HTML <canvas> 标签用于使用脚本绘制图形、动画等。
以下是 <canvas> 标签的属性 −
| 属性 | 值 | 描述 |
|---|---|---|
| height | pixels | 指定画布的高度。 |
| width | pixels | 指定画布的宽度。 |
示例
您可以尝试运行以下代码来实现 <canvas> 标签并创建图形 −
<!DOCTYPE html>
<html>
<head>
<title>HTML Canvas Tag</title>
</head>
<body>
<canvas id = "newCanvas">Your browser does not support canvas tag.</canvas>
<script>
var c = document.getElementById('newCanvas');
var ctx = c.getContext('2d');
ctx.fillStyle = '#00AEEF';
ctx.fillRect(0,0,180,50);
</script>
</body>
</html>
相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

