aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/canvasrenderingcontext2d/strokerect/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/zh-cn/web/api/canvasrenderingcontext2d/strokerect/index.html')
-rw-r--r--files/zh-cn/web/api/canvasrenderingcontext2d/strokerect/index.html110
1 files changed, 110 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/canvasrenderingcontext2d/strokerect/index.html b/files/zh-cn/web/api/canvasrenderingcontext2d/strokerect/index.html
new file mode 100644
index 0000000000..6cb5bf9f54
--- /dev/null
+++ b/files/zh-cn/web/api/canvasrenderingcontext2d/strokerect/index.html
@@ -0,0 +1,110 @@
+---
+title: CanvasRenderingContext2D.strokeRect()
+slug: Web/API/CanvasRenderingContext2D/strokeRect
+tags:
+ - API
+ - Canvas
+translation_of: Web/API/CanvasRenderingContext2D/strokeRect
+---
+<div>{{APIRef}}</div>
+
+<p><code><strong>CanvasRenderingContext2D</strong></code><strong><code>.strokeRect()</code></strong> 是 Canvas 2D API 在 canvas 中,使用当前的绘画样式,描绘一个起点在 <em>(x, y)</em> 、宽度为<em> w</em> 、高度为 <em>h</em> 的矩形的方法。</p>
+
+<p>此方法直接绘制到画布而不修改当前路径,因此任何后续{{domxref("CanvasRenderingContext2D.fill()", "fill()")}} 或{{domxref("CanvasRenderingContext2D.stroke()", "stroke()")}}调用对它没有影响。</p>
+
+<h2 id="语法">语法</h2>
+
+<pre class="syntaxbox">void <var><em>ctx</em>.strokeRect(x, y, width, height);</var>
+</pre>
+
+<p><code>strokeRect()</code>方法绘制一个描边矩形,其起点为<code>(x, y)</code> ,其大小由宽度和高度指定。</p>
+
+<h3 id="参数">参数</h3>
+
+<dl>
+ <dt><code>x</code></dt>
+ <dd>矩形起点的 x 轴坐标。</dd>
+ <dt><code>y</code></dt>
+ <dd>矩形起点的 y 轴坐标。</dd>
+ <dt><code>width</code></dt>
+ <dd>矩形的宽度。正值在右侧,负值在左侧。</dd>
+ <dt><code>height</code></dt>
+ <dd>矩形的高度。正值在下,负值在上。</dd>
+</dl>
+
+<h2 id="示例">示例</h2>
+
+<h3 id="一个简单的填充矩形">一个简单的填充矩形</h3>
+
+<p>这是一段使用 <code>strokeRect</code> 方法的简单的代码片段。</p>
+
+<h4 id="HTML">HTML</h4>
+
+<pre class="brush: html">&lt;canvas id="canvas"&gt;&lt;/canvas&gt;
+</pre>
+
+<h4 id="JavaScript">JavaScript</h4>
+
+<p>矩形的左上角是(20,10)。它的宽度为160,高度为100。</p>
+
+<pre class="brush: js">const canvas = document.getElementById('canvas');
+const ctx = canvas.getContext('2d');
+ctx.strokeStyle = 'green';
+ctx.strokeRect(20, 10, 160, 100);</pre>
+
+<h4 id="结果">结果</h4>
+
+<p>{{ EmbedLiveSample('一个简单的填充矩形', 700, 180) }}</p>
+
+<h3 id="应用多种上下文设置">应用多种上下文设置</h3>
+
+<p>此示例绘制一个带有阴影和粗斜面轮廓的矩形。</p>
+
+<h4 id="HTML_2">HTML</h4>
+
+<pre class="brush: html"><code>&lt;canvas id="canvas"&gt;&lt;/canvas&gt;</code></pre>
+
+<h4 id="JavaScript_2">JavaScript</h4>
+
+<pre class="brush: js">const canvas = document.getElementById('canvas');
+const ctx = canvas.getContext('2d');
+ctx.shadowColor = '#d53';
+ctx.shadowBlur = 20;
+ctx.lineJoin = 'bevel';
+ctx.lineWidth = 15;
+ctx.strokeStyle = '#38f';
+ctx.strokeRect(30, 30, 160, 90);</pre>
+
+<h4 id="结果_2">结果</h4>
+
+<p>{{ EmbedLiveSample('应用多种上下文设置', 700, 180) }}</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-strokerect", "CanvasRenderingContext2D.strokeRect")}}</td>
+ <td>{{Spec2('HTML WHATWG')}}</td>
+ <td> </td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+<p>{{Compat("api.CanvasRenderingContext2D.strokeRect")}}</p>
+
+<h2 id="参见">参见</h2>
+
+<ul>
+ <li>接口定义,{{domxref("CanvasRenderingContext2D")}}</li>
+ <li>{{domxref("CanvasRenderingContext2D.strokeStyle")}}</li>
+ <li>{{domxref("CanvasRenderingContext2D.clearRect()")}}</li>
+ <li>{{domxref("CanvasRenderingContext2D.fillRect()")}}</li>
+</ul>