绘制一个线宽为 10 像素的矩形:
<canvas id="myCanvas" width="300" height="150" style="border:1px solid #d3d3d3;"> Your browser does not support the HTML5 canvas tag.</canvas> <script> var c = document.getElementById("myCanvas"); var ctx = c.getContext("2d"); ctx.lineWidth = 10; ctx.strokeRect(20, 20, 80, 100); </script>
JavaScript:
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.lineWidth = 10;
ctx.strokeRect(20, 20, 80, 100);
表中的数字指定了完全支持该属性的第一个浏览器版本。
| 属性 Property |
|
|
|
|
|
|---|---|---|---|---|---|
| lineWidth | Yes | 9.0 | Yes | Yes | Yes |
lineWidth 属性设置或返回当前线宽,以像素为单位。
| 默认值: | 1 |
|---|---|
| JavaScript 语法: | context.lineWidth=number; |
| 值 Value | 描述 Description |
|---|---|
| number | 当前线宽,以像素为单位 |