javascript - How to make a part of canvas clickable? -


what want make part of canvas clickable. , when click function gets called. how do in javascript?

you'll have bind click event whole canvas , detect position of cursor on click, , then, if cursor within dimensions, execute function.

here's fiddle, using div example: http://jsfiddle.net/r8red/17/

function testandexecute(elem, event, area, func){     // area relative page :     // var area = {     //     x0: 60,     //     y0: 60,     //     x1: 100,     //     y1: 100     // }         elem.addeventlistener(event, function(e){         var page = {             x: e.pagex,             y: e.pagey         }         if(page.x >= area.x0 && page.x <= area.x1 && page.y >= area.y0 && page.y <= area.y1){             func();         }     }); } 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -