--- title: CanvasRenderingContext2D.fill() slug: Web/API/CanvasRenderingContext2D/fill translation_of: Web/API/CanvasRenderingContext2D/fill ---
CanvasRenderingContext2D
.fill()
是 Canvas 2D API 根据当前的填充样式,填充当前或已存在的路径的方法。采取非零环绕或者奇偶环绕规则。
void ctx.fill(); void ctx.fill(fillRule); void ctx.fill(path, fillRule);
fillRule
path
fill
方法这是一段简单的代码片段, 使用 fill
方法填充路径。
<canvas id="canvas"></canvas>
var canvas = document.getElementById("canvas"); var ctx = canvas.getContext("2d"); ctx.rect(10, 10, 100, 100); ctx.fill();
修改下面的代码并在线查看 canvas 变化:
{{ EmbedLiveSample('Playable_code', 700, 360) }}
Specification | Status | Comment |
---|---|---|
{{SpecName('HTML WHATWG', "scripting.html#dom-context-2d-fill", "CanvasRenderingContext2D.fill")}} | {{Spec2('HTML WHATWG')}} |
{{ CompatibilityTable() }}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | {{ CompatVersionUnknown() }} | {{ CompatVersionUnknown() }} | {{ CompatVersionUnknown() }} | {{ CompatVersionUnknown() }} | {{ CompatVersionUnknown() }} |
Path parameter | {{ CompatVersionUnknown() }} | {{ CompatGeckoDesktop(31) }} | {{ CompatNo }} | {{ CompatVersionUnknown() }} | {{ CompatNo }} |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | {{ CompatVersionUnknown() }} | {{ CompatVersionUnknown() }} | {{ CompatVersionUnknown() }} | {{ CompatVersionUnknown() }} | {{ CompatVersionUnknown() }} | {{ CompatVersionUnknown() }} |
Path parameter | {{ CompatUnknown() }} | {{ CompatUnknown() }} | {{ CompatGeckoMobile(31) }} | {{ CompatUnknown() }} | {{ CompatUnknown() }} | {{ CompatUnknown() }} |