diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/canvasrenderingcontext2d/linewidth/index.html | |
parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip |
initial commit
Diffstat (limited to 'files/zh-cn/web/api/canvasrenderingcontext2d/linewidth/index.html')
-rw-r--r-- | files/zh-cn/web/api/canvasrenderingcontext2d/linewidth/index.html | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/canvasrenderingcontext2d/linewidth/index.html b/files/zh-cn/web/api/canvasrenderingcontext2d/linewidth/index.html new file mode 100644 index 0000000000..12216cccb7 --- /dev/null +++ b/files/zh-cn/web/api/canvasrenderingcontext2d/linewidth/index.html @@ -0,0 +1,101 @@ +--- +title: CanvasRenderingContext2D.lineWidth +slug: Web/API/CanvasRenderingContext2D/lineWidth +tags: + - API + - Canvas +translation_of: Web/API/CanvasRenderingContext2D/lineWidth +--- +<div>{{APIRef}}</div> + +<p>The <code><strong>CanvasRenderingContext2D</strong></code><strong><code>.lineWidth</code></strong> 是 Canvas 2D API 设置线段厚度的属性(即线段的宽度)。</p> + +<div class="blockIndicator note"> +<p><strong>Note:</strong>线可以通过{{domxref("CanvasRenderingContext2D.stroke()", "stroke()")}}, {{domxref("CanvasRenderingContext2D.strokeRect()", "strokeRect()")}}, 和{{domxref("CanvasRenderingContext2D.strokeText()", "strokeText()")}} 方法绘制。</p> +</div> + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox"><var><em>ctx</em>.lineWidth = value;</var></pre> + +<h3 id="选项">选项</h3> + +<dl> + <dt><code>value</code></dt> + <dd>描述线段宽度的数字。 0、 负数、 {{jsxref("Infinity")}} 和 {{jsxref("NaN")}} 会被忽略。</dd> +</dl> + +<h2 id="示例">示例</h2> + +<h3 id="改变线宽">改变线宽</h3> + +<p>此示例使用15个单位的线宽绘制直线和矩形。</p> + +<h4 id="HTML">HTML</h4> + +<pre class="brush: html"><canvas id="canvas"></canvas> +</pre> + +<h4 id="JavaScript">JavaScript</h4> + +<pre class="brush: 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(); +</pre> + +<h4 id="结果">结果</h4> + +<p>{{ EmbedLiveSample('改变线宽', 700, 180) }}</p> + +<h3 id="更多示例">更多示例</h3> + +<p>有关此属性的更多示例和说明,请参阅在“画布教程”中的<a href="/zh-CN/docs/Web/API/Canvas_API/Tutorial/Applying_styles_and_colors">使用样式和颜色</a>。</p> + +<h2 id="规范描述">规范描述</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('HTML WHATWG', "scripting.html#dom-context-2d-linewidth", "CanvasRenderingContext2D.lineWidth")}}</td> + <td>{{Spec2('HTML WHATWG')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<p>{{Compat("api.CanvasRenderingContext2D.lineWidth")}}</p> + +<h3 id="WebKitBlink-specific_注解">WebKit/Blink-specific 注解</h3> + +<ul> + <li>在基于 WebKit- 和 Blink- 的浏览器中,除了此属性外,实现了一个不标准的并且不赞成使用的方法 <code>ctx.setLineWidth()</code> 。</li> +</ul> + +<h3 id="Gecko-specific_注解">Gecko-specific 注解</h3> + +<ul> + <li>从 Gecko 2.0 {{geckoRelease("2.0")}}版本开始, 设置<code>lineWidth</code> 为负数不再抛出异常,所有非正数值都会被忽略。</li> +</ul> + +<h2 id="参见">参见</h2> + +<ul> + <li>接口定义, {{domxref("CanvasRenderingContext2D")}}</li> + <li>{{domxref("CanvasRenderingContext2D.lineCap")}}</li> + <li>{{domxref("CanvasRenderingContext2D.lineJoin")}}</li> + <li><a href="/zh-CN/docs/Web/API/Canvas_API/Tutorial/Applying_styles_and_colors">使用样式和颜色</a></li> +</ul> |