--- title: CanvasRenderingContext2D.clearHitRegions() slug: Web/API/CanvasRenderingContext2D/clearHitRegions translation_of: Web/API/CanvasRenderingContext2D/clearHitRegions ---
CanvasRenderingContext2D
.clearHitRegions()
是 Canvas 2D API 在画布中删除所有点击区域的方法。
void ctx.clearHitRegions();
clearHitRegions
方法这仅是一段简单的使用 clearHitRegions
方法的代码片段。
<canvas id="canvas"></canvas>
var canvas = document.getElementById("canvas"); var ctx = canvas.getContext("2d"); // set some hit regions ctx.addHitRegion({id: "eyes"}); ctx.addHitRegion({id: "nose"}); ctx.addHitRegion({id: "mouth"}); // remove them altogether from the canvas ctx.clearHitRegions();
Specification | Status | Comment |
---|---|---|
{{SpecName('HTML WHATWG', "scripting.html#dom-context-2d-clearhitregions", "CanvasRenderingContext2D.clearHitRegions")}} | {{Spec2('HTML WHATWG')}} |
{{CompatibilityTable}}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | {{CompatVersionUnknown}}[1] | {{CompatGeckoDesktop(38)}} [2] | {{ CompatNo }} | {{ CompatNo }} | {{ CompatNo }} |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | {{ CompatNo }} | {{ CompatNo }} | {{CompatGeckoMobile(38)}} [2] | {{ CompatNo }} | {{ CompatNo }} | {{ CompatNo }} |
ExperimentalCanvasFeatures
标志为 true
进行启用。canvas.hitregions.enabled
为 true。