Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make absolute positioned image area maps clickable with mouse?

I have several images positioned on top of each other using absolute positioning. These images are partially transparent, and have a html area and map to make only the visible parts clickable. In jQuery, I have attached mouse events to the area tags.

This works well for one image: mouseenter and mouseleave fire only when the mapped part of the image is entered.

The problem is that it only works for the top image. For all others, it doesn't fire events not does CSS hover work, because there is another image on top of it. This despite the fact that the areas do not overlap and maps are in front of the images.

Here is a demonstration of the problem: http://markv.nl/stack/imgmap2/

like image 974
Mark Avatar asked May 28 '12 10:05

Mark


2 Answers

You can place a single, completely transparent image on top of all individual images, and attach all imagemap areas to that image. It will act as a capturing element for the mouse events, and you can still change all individual images.

like image 95
lanzz Avatar answered Nov 15 '22 18:11

lanzz


It's not a direct answer/solution...

Why don't you use a canvas/SVG to do the drawing? There is plenty of libraries which make the task easy. One of them is RaphaëlJS (check this example). The advantage of this library is that it allows mouse interactivity.

Another library you may consider is EaselJS, but it doesn't work in the browsers not supporting <canvas>, so no IE < 9 support.

like image 37
strah Avatar answered Nov 15 '22 19:11

strah