--- title: CanvasRenderingContext2D.removeHitRegion() slug: Web/API/CanvasRenderingContext2D/removeHitRegion translation_of: Web/API/CanvasRenderingContext2D/removeHitRegion ---
CanvasRenderingContext2D
.removeHitRegion()
是 Canvas 2D API 删除canvas中已存在的碰撞区域的方法。
void ctx.removeHitRegion(id);
removeHitRegion
方法这是一段使用 removeHitRegion
方法的简单的代码片段。
<canvas id="canvas"></canvas>
var canvas = document.getElementById("canvas"); var ctx = canvas.getContext("2d"); // set a hit region ctx.addHitRegion({id: "eyes"}); // remove it from the canvas ctx.removeHitRegion("eyes");
Specification | Status | Comment |
---|---|---|
{{SpecName('HTML WHATWG', "scripting.html#dom-context-2d-removehitregion", "CanvasRenderingContext2D.removeHitRegion")}} | {{Spec2('HTML WHATWG')}} |
{{CompatibilityTable}}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | {{CompatVersionUnknown}}[1] | {{CompatGeckoDesktop(30)}} [2] | {{ CompatNo }} | {{ CompatNo }} | {{ CompatNo }} |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | {{ CompatNo }} | {{ CompatNo }} | {{CompatGeckoDesktop(30)}} [2] | {{ CompatNo }} | {{ CompatNo }} | {{ CompatNo }} |
ExperimentalCanvasFeatures
为 true
进行启用。canvas.hitregions.enabled
为 true。