CanvasRenderingContext2D.removeHitRegion()

已废弃: This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.

CanvasRenderingContext2D.removeHitRegion() 是 Canvas 2D API 删除canvas中已存在的碰撞区域的方法。

语法

void ctx.removeHitRegion(id);

参数

id
DOMString字符串,描述将要被删除区域的 id。

示例

使用 removeHitRegion 方法

这是一段使用 removeHitRegion 方法的简单的代码片段。

HTML

<canvas id="canvas"></canvas>

JavaScript

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
HTML Living Standard
CanvasRenderingContext2D.removeHitRegion
Living Standard

浏览器兼容性

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help! (en-US)

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support (Yes)[1] 30 (30) [2] 未实现 未实现 未实现
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support 未实现 未实现 30 (30) [2] 未实现 未实现 未实现

兼容性注解

  • [1] 此特性受控于特性标识。 设置标识 ExperimentalCanvasFeaturestrue 进行启用。
  • [2] 此特性受控于特性偏好设置。在 about:config 中, 设置 canvas.hitregions.enabled 为 true。

参见