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.
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
region | Chrome
Full support
Yes
| Edge
Full support
≤79
| Firefox
Full support
30
| 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
| 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.