Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find out which object was clicked on a html5 Canvas

Suppose I have a html5/canvas application in which I can place objects on a drawing-canvas. Some kind of diagram editor, something like Visio (but much simpler)

Is there a framework which helps me find which object is clicked/dragged?

An option is to capture the click-event and iterate over all my objects (in a semi-smart way) and check if it is clicked/dragged, but I hate to reinvent the wheel!

like image 372
Dribbel Avatar asked Oct 20 '10 17:10

Dribbel


1 Answers

The short version is that Canvas itself keeps track of none of that.

If you don't want to reinvent the wheel, start with my sample code from the tutorial "Making and Moving Selectable Shapes on an HTML5 Canvas: A Simple Example." It provides a good introduction and platform for clicking and dragging.

like image 175
Simon Sarris Avatar answered Oct 07 '22 01:10

Simon Sarris