Creates a hit region.
Method of apis/canvas/CanvasRenderingContext2Dapis/canvas/CanvasRenderingContext2D
Syntax context.addHitRegion(options);
Parameters options
This parameter is of type HitRegionOptions. It can have following members:
No return value
Examplessimple click detection
var canvas = document.getElementById( "mycanvas" );
var ctx = canvas.getContext( "2d" );
ctx.fillStyle = "lime";
ctx.beginPath( );
ctx.rect( 10, 10, 100, 100 );
ctx.fill( );
try {
ctx.addHitRegion( {"id": "limeRectangle" } );
} catch( e ) {
alert( "your browser does not support hit regions" );
}
canvas.onclick = function( e ) {
if( e.region ) {
alert( "clicked on: " + e.region );
}
};
Related specifications
A hit region is an arbitrary rectangular area on the canvas that responds to user events, with the goal of simplifying event detection.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4