Html Codes: Canvas- Select an Object by Mouse Click (Hit Detection)
One of the most important tools connecting users and the computers is mouse click. HTML5 Canvas, like other programming languages, has capability to detect whether a mouse click is in specified object (path) or not. But before that we must transform the mouse position based on the canvas element coordinates. Then a hit detector for each object can be created separately; and the object graphical style can change when it is selected. In the following example, click on one of the objects to see how HTML5 Canvas Mouse click detector works. If you click outside of all objects, all shapes styles returns to its default gray.
If you don't know how to use this code or need more information Click here!
![]() | You can leave comments once you sign in/up. |