I am trying to create an image map and it works okay. I am able to hover over an image area and it links to another page.
Instead of href link, is it possible to display popup text instead? So, in my example below, clicking on the left eye or Mouth should produce popup text.
Here is an example of how my popup text should look.
https://frankmanno.com/ideas/css-imagemap/index_js.html
Here is my code –
<div id="container">
<div id="image_container">
<img src="http://tinypic.com/images/goodbye.jpg" usemap="#image_map">
<map name="image_map">
<area alt="Left Eye" title="Left Eye" href="https://www.yahoo.com/" coords="118,36,148,80" shape="rect">
<area alt="Mouth" title="Mouth" href="https://www.yahoo.com/" coords="121,84,198,118" shape="rect">
</map>
</div>
2
Answers
You have to change
href
attribute totitle
in thearea
tag.After applying this change, when you hover over this area, the popup text contained in the
title
attribute will be displayed.If you need a more advanced effect, you’ll have to use JS to display similar cases.
To add a beautiful popup with X close button, as you mentioned, you need to add it separately, for example as a
div
element and place it in correct position. Then hide it withdisplay: none
orvisibility: hidden
initially. And add amouseenter
event listener (element.setEventListener("onmouseenter", () => ...)
) to yourarea
element, and update style of your popup to make it visible.Additionally, you may want to hide the popup, and to achieve that, you’ll need a
mouseleave
event listener, which will apply the hidden styles to your popup once again.