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>
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
region
|
Chrome
Yes
Disabled
|
Edge
≤79
Disabled
|
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 |
完整支持
不支持
用户必须明确启用此特征。
MouseEvent