CanvasRenderingContext2D.clearHitRegions()

已废弃
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.clearHitRegions() 是 Canvas 2D API 在画布中删除所有点击区域的方法。

语法

void ctx.clearHitRegions();

示例

使用 clearHitRegions 方法

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

HTML

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

JavaScript

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
HTML Living Standard
CanvasRenderingContext2D.clearHitRegions
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!
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support (Yes)[1] 38 (38) [2] 未实现 未实现 未实现
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support 未实现 未实现 38.0 (38) [2] 未实现 未实现 未实现

兼容性注解

  • [1] 此特性需要一个特性标志。 设置 ExperimentalCanvasFeatures 标志为 true 进行启用。
  • [2] 此特性需要一个特性偏好设置。 在 about:config中设置 canvas.hitregions.enabled 为 true。

参见