The MouseEvent.region
read-only property returns the id of the canvas hit region affected by the event. If no hit region is affected, null
is returned.
Syntax
var hitRegion = instanceOfMouseEvent.region
Return value
A DOMString
representing the id of the hit region.
Example
Example of using the event.region
combined with CanvasRenderingContext2D.addHitRegion()
method.
<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>
Browser compatibility
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.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
region
|
Chrome Full support Yes Full support Yes Disabled' This feature is behind the |
Edge Full support ≤79 Full support ≤79 Disabled' From version ≤79: this feature is behind the |
Firefox Full support 30 Full support 30 Disabled' From version 30: this feature is behind the |
IE
No support No |
Opera
No support No |
Safari
No support No |
WebView Android
No support No |
Chrome Android
No support No |
Firefox Android Full support 30 Full support 30 Disabled' From version 30: this feature is behind the |
Opera Android
No support No |
Safari iOS
No support No |
Samsung Internet Android
No support No |
Legend
- Full support
- Full support
- No support
- No support
- User must explicitly enable this feature.'
- User must explicitly enable this feature.
See also
MouseEvent.region by Mozilla Contributors is licensed under CC-BY-SA 2.5.