Detect mouseover of certain points within an HTML canvas?

You could handle the mousemove event and get the x,y coordinates from the event. Then you’ll probably have to iterate over all your paths to test if the point is over the path. I had a similar problem that might have some code you could use.

Looping over things in this way can be slow, especially on IE. One way you could potentially speed it up – and this is a hack, but it would be quite effective – would be to change the color that each path is drawn with so that it is not noticeable by humans but so that each path is drawn in a different color. Have a table to look up colors to paths and just look up the color of the pixel under the mouse.

Leave a Comment