MDN’s new design is in Beta! A sneak peek: https://blog.mozilla.org/opendesign/mdns-new-design-beta/

CanvasRenderingContext2D.lineWidth

翻譯不完整。請協助 翻譯此英文文件

CanvasRenderingContext2D.lineWidth 為 Canvas 2D API 設定線段粗細的屬性。可藉此屬性取得目前的線段粗細值(預設為 1.0)。設定此屬性時,零、負數、Infinity 以及 NaN 都會被忽略,而其他正確的值將會被設定成屬性值。

可參考 Canvas Tutorial 中的 Applying styles and color 章節。

語法

ctx.lineWidth = value;

選項

value
A number specifying the line width in space units. Zero, negative, Infinity and NaN values are ignored.

範例

使用 lineWidth 屬性

This is just a simple code snippet using the lineWidth property to draw lines with a rounded end.

HTML

<canvas id="canvas"></canvas>

JavaScript

var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');

ctx.beginPath();
ctx.moveTo(0, 0);
ctx.lineWidth = 15;
ctx.lineTo(100, 100);
ctx.stroke();

Edit the code below and see your changes update live in the canvas:

規範

Specification Status Comment
WHATWG HTML Living Standard
The definition of 'CanvasRenderingContext2D.lineWidth' in that specification.
Living Standard  

瀏覽器相容性

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari
Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes)
Feature Android Chrome for Android Edge Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes) (Yes)
  • In WebKit- and Blink-based Browsers, a non-standard and deprecated method ctx.setLineWidth() is implemented besides this property.

Gecko-specific notes

  • Starting Gecko 2.0 (Firefox 4 / Thunderbird 3.3 / SeaMonkey 2.1), setting lineWidth to a negative value no longer throws an exception; instead, it properly ignores non-positive values.

參見

文件標籤與貢獻者

 此頁面的貢獻者: jackblackevo
 最近更新: jackblackevo,