Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I'm trying to create an ImageMap that changes as users mouse over certain parts of the image. I have the following ImageMap where users are able to click on a color and go to a different page:

http://i.stack.imgur.com/hXJSC.png[^]

I created 4 additional images that are all the same size, and would like to swap out the image on mouseover. For example, when I mouseover the blue I want the image to look like this:

http://i.stack.imgur.com/gwb3q.png[^]

And when I mouse over the green part, I want it to look like this:

http://i.stack.imgur.com/EptjR.png[^]

What is the best way to accomplish what I'm trying to do? I planned on using asp.net for the implementation but have been unable to do so.

Here is the code for the ImageMap/hotspot:

ASP.NET
<asp:ImageMap ID="ImageMap1" runat="server" Height="300px" HotSpotMode="Navigate" ImageAlign="Middle" ImageUrl="~/images/hotspot-logo.png" Width="303px">
                            <asp:PolygonHotSpot AlternateText="orange" Coordinates="151,8,220,78,150,150,78,78" HotSpotMode="Navigate" NavigateUrl="~/orange.aspx" />
                            <asp:PolygonHotSpot AlternateText="red" Coordinates="220,78,150,150,222,222,292,150" HotSpotMode="Navigate" NavigateUrl="~/red.aspx" />
                            <asp:PolygonHotSpot AlternateText="green" Coordinates="78,78,150,150,78,222,8,150" HotSpotMode="Navigate" NavigateUrl="~/green.aspx" />
                            <asp:PolygonHotSpot AlternateText="blue" Coordinates="150,150,78,222,150,292,222,222" HotSpotMode="Navigate" NavigateUrl="~/blue.aspx" />
                        </asp:ImageMap>
Posted
Updated 10-May-17 5:05am
Comments
Member 11795696 26-Jun-15 18:47pm    
It doesn't have to be asp.net if that's not possible. Does anyone have another suggestion I could use? All I need is for the image to change as the user mouses over each hotspot.

The functionality you want has nothing to do with ImageMap.

You could use image map, but only for the hit test, which is actually the sole purpose of the image map. Unfortunately, your event is not click, but mouse over. Also, it's really bad to run it on server, because it will cause the postback, too slow for a click which is supposed to change image immediately. You really need to do it all on the client side using JavaScript.

The simple solution is: with JavaScript: handle the event mousemove. Depending on mouse coordinates, replace the current image with another image, via modification of the value of the src attribute. You will need a separate image for each combination you want to use.
Please see: http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-eventgroupings-mouseevents[^].

It can be done easily if you use jQuery. You can use .attr("src") of the image jQuery wrapper and replace its value using .replace(). You can find a simple example here: http://stackoverflow.com/questions/11130008/dynamically-replace-image-source-with-jquery[^].

And this is how you handle the event using jQuery: https://api.jquery.com/mousemove[^].

If you need to learn jQuery (highly recommended), please see:
http://en.wikipedia.org/wiki/JQuery,
http://jquery.com,
http://learn.jquery.com,
http://learn.jquery.com/using-jquery-core,
http://learn.jquery.com/about-jquery/how-jquery-works (start from here).

—SA
 
Share this answer
 
please try java script or css.........................
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900