A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://webplatform.github.io/docs/apis/canvas/CanvasRenderingContext2D/addHitRegion below:

addHitRegion ยท WebPlatform Docs

addHitRegion Summary

Creates a hit region.

Method of apis/canvas/CanvasRenderingContext2Dapis/canvas/CanvasRenderingContext2D

Syntax
 context.addHitRegion(options);
Parameters options
Data-type
Object

This parameter is of type HitRegionOptions. It can have following members:

Return Value

No return value

Examples

simple 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
W3C HTML Canvas 2D Specification
W3C Candidate Recommendation
W3C HTML Canvas 2D Specification
W3C Candidate Recommendation
Notes

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