MouseEvent.region read-only property returns the id of the canvas hit region affected by the event. If no hit region is affected, null 被返回。

句法

var hitRegion = instanceOfMouseEvent.region
					

返回值

A DOMString representing the id of the hit region.

范例

Example of using the event.region combined with CanvasRenderingContext2D . addHitRegion() 方法。

<canvas id="canvas"></canvas>
<script>
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
ctx.beginPath();
ctx.arc(70, 80, 10, 0, 2 * Math.PI, false);
ctx.fill();
ctx.addHitRegion({id: "circle"});
canvas.addEventListener("mousemove", function(event){
  if(event.region) {
    console.log("hit region: " + event.region);
  }
});
</script>
					

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
region Chrome Yes Disabled
Yes Disabled
Disabled This feature is behind the ). To change preferences in Chrome, visit
Edge ≤79 Disabled
≤79 Disabled
Disabled From version ≤79: this feature is behind the Experimental Web Platform Features preference (needs to be set to true ).
Firefox 30 IE No Opera No Safari No WebView Android No Chrome Android No Firefox Android 30 Opera Android No Safari iOS No Samsung Internet Android No

图例

完整支持

完整支持

不支持

不支持

用户必须明确启用此特征。

用户必须明确启用此特征。

另请参阅

元数据

  • 最后修改: