HTML Canvas 的 strokeRect() 方法
htmlweb developmentfront end technology更新于 2025/7/17 16:44:17
HTML Canvas 的 strokeRect() 方法用于在网页上创建一个矩形。<canvas> 元素允许您使用 JavaScript 在网页上绘制图形。每个 Canvas 都有两个元素,分别描述 Canvas 的高度和宽度。
以下是语法 −
context.strokeRect(p,q,width,height);
以上,
- p − 矩形左上角的 x 坐标
- q − 矩形左上角的 y 坐标
- width −矩形的宽度
- height − 矩形的高度
现在让我们看一个实现画布 strokeStyle 属性的示例 −
示例
<!DOCTYPE html>
<html>
<body>
<canvas id="newCanvas" width="550" height="400" style="border −2px solid orange;"></canvas>
<script>
var c = document.getElementById("newCanvas");
var ctx = c.getContext("2d");
ctx.strokeRect(120, 120, 220, 120);
</script>
</body>
</html>
输出

相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

