CanvasRenderingContext2D:lineWidth 属性
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Canvas 2D API 的 CanvasRenderingContext2D.lineWidth
属性用于设置线宽。
备注:
线可以通过 stroke()
、strokeRect()
和 strokeText()
方法绘制。
值
示例
改变线宽
此示例使用 15 个单位的线宽绘制直线和矩形。
HTML
html
<canvas id="canvas"></canvas>
JavaScript
js
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext("2d");
ctx.lineWidth = 15;
ctx.beginPath();
ctx.moveTo(20, 20);
ctx.lineTo(130, 130);
ctx.rect(40, 40, 70, 70);
ctx.stroke();
结果
更多示例
规范
Specification |
---|
HTML Standard # dom-context-2d-linewidth-dev |
浏览器兼容性
BCD tables only load in the browser