d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Image Map With Popup Images On Hover > Need Help/advice On How To Do
Add Reply New Topic New Poll
Member
Posts: 400
Joined: May 2 2018
Gold: 500.00
May 27 2020 05:50am
What seems like half a lifetime ago I used to know how to code HTML and CSS. Then I stopped. Now I've started again and, man, has coding changed with the advent of HTML5 and CSS3. I need some help.

I'm working on a personal project where I want to emulate the inventory and character screens of my characters on a web page – just like when we're viewing our characters and mousing over our gear and D2 shows us what the stats of our gear is. I figure an image map with popup images on hover is the way to do it.

1. You mouse over the image of an item on the image map (the "hot spot") and a pop up image showing the stats of the item appears on the screen;
2. You move your mouse off of the image and the image is gone from the screen.

Aside from keeping the popup within the boundaries of the viewport and perhaps having a smooth fade in/fade out effect for the pop up image, that's all I'm after.

Here is an example of how I envision this:



Years ago I used to be able to do exactly what I just described using JavaScript but the code I used then is now outdated.

Code
<div align=center><img src="images/mysticzon.png" width=920 height=672 border=0 usemap="#mysticzon">
<map name="mysticzon"></div>

<area shape="rect" coords="480,118,550,248" href="javascript:void(null)" onfocus="if(this.blur)this.blur()" onMouseOver="writetxt('<div><img src=mysticzon-titans.png border=0 height=412 width=480></div>')" onMouseOut="writetxt(0)">
</map>


Since this is just for me, I don't need this to be cross-browser compatible. I use Chrome and that's all this has to work in. I have an old but still reliable image edit app that will outline the image map's hot spot co-ordinates, so I'm good to go in that department.

I'd appreciate it very much if anybody can point me in the right direction of how to make this work.

This post was edited by Mysticzon on May 27 2020 06:16am
Member
Posts: 9,595
Joined: Nov 24 2015
Gold: Locked
May 28 2020 07:53am
Member
Posts: 400
Joined: May 2 2018
Gold: 500.00
May 28 2020 01:28pm
While I sincerely thank you for your interest in my question, what you have provided me with is not helpful.

I need a script or some kind of code that will produce an image popup when the mouse moves over an image map's "hot spot" coordinates.

My knowledge of JQuery is next to zero, but it looks like what you have provided me with is an image popup when the mouse moves over a text link.

Even so, because of my limited knowledge of JQuery, I don't even know where to begin to try to adapt your JQuery script to my needs.

Also, not sure if this matters to you, but you are using a broken link in line 4 of your script.

Once again, thank you very much for your interest.




Member
Posts: 28
Joined: Oct 23 2019
Gold: 0.00
May 29 2020 05:48am
Member
Posts: 983
Joined: Jan 25 2013
Gold: 2.09
May 30 2020 12:07am
Java script is used for these actions,

https://www.w3schools.com/js/default.asp

<button type="button"
onclick="document.getElementById('demo').innerHTML = Date()">
Click me to display Date and Time.</button>


onclick= or onhover=
Member
Posts: 400
Joined: May 2 2018
Gold: 500.00
May 30 2020 01:58pm
Quote (MonsieurPorc @ May 29 2020 07:48am)


Hello and thank you for your interest in my question.

With my extremely limited knowledge of JQuery, I tried to recreate the example shown in your first link even though the example failed to do what it was intended to do: display a popup image when the mouse is moved over a "hot spot" coordinate on an image map. Nonetheless, I figured if i could recreate the example successfully, then maybe I could adapt the script to suit my own image map and images.

In Line 1
Code
<div class="sitebox">
"sitebox" is undefined. Either it's a redundant tag or something really is missing that is preventing this example from working.

In Line 8
Code
<img id="image" src="http://images.pictureshunt.com/pics/m/mouse-8557.JPG" />
is a broken link, so I substituted it with my own image.

That having been said, here is what I came up with:

Code
<!DOCTYPE HTML>

<html>
<head>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

<script type="text/javascript">
/*
http://stackoverflow.com/questions/40497584/imagemap-on-hover-display-image/40526150#40526150
*/

$("area").mousemove(function(e) {
$("#image").attr("src", $(this).data("image")).show().css({
left: e.pageX + 10,
top: e.pageY + 10
});
});
$("area").mouseout(function(e) {
$("#image").hide();
});
</script>


<style>

#image{
position:absolute;
display:none;
}
</style>

</head>

<body>

<div class="sitebox">
<img name="aerialmap" src="http://www.getmapping.com/sites/default/files/styles/post_image/public/quick_media/getmapping_aerialimagery_vertical_hamptoncourt_1_0.jpg?itok=tNmyWk21" usemap="#aerial2" style="border:5px solid #535353;">

<map name="aerial2">
<area shape="poly" coords="531,287,538,321,610,301,601,270" href="#" onclick="return false" title="building 1" data-image="https://placeholdit.imgix.net/~text?txtsize=40&bg=ff9900&txtclr=ffffff&txt=01&w=70&h=70">
<area shape="poly" coords="196,246,240,255,213,384,166,376" href="#" onclick="return false" title="Building 2" data-image="https://placeholdit.imgix.net/~text?txtsize=40&bg=ff0000&txtclr=ffffff&txt=02&w=70&h=70">
</map>
</div>
<img id="image" src="http://theinspirationgallery.com/D2-2020/mysticzon-titans.png" />

</body>
</html>


Which can be seen on my domain: https://bit.ly/3eyMDRZ

As you can see, nothing is working, and I don't possess the coding knowledge to troubleshoot or adapt this script.

I appreciate the time you took to try and help me with my project.
Member
Posts: 400
Joined: May 2 2018
Gold: 500.00
May 30 2020 02:03pm
Quote (ryanfarva @ May 30 2020 02:07am)
Java script is used for these actions,

https://www.w3schools.com/js/default.asp

<button type="button"
onclick="document.getElementById('demo').innerHTML = Date()">
Click me to display Date and Time.</button>


onclick= or onhover=


I believe you posted in the wrong thread. If not, then I have no idea what you are trying to accomplish but thanks for playing. <_<
Member
Posts: 28
Joined: Oct 23 2019
Gold: 0.00
May 31 2020 06:09am
Sorry i didnt try the code before sending you a link, this seems to work for me tho.

Code
<!DOCTYPE HTML>

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<style>
#image{
position:absolute;
display:none;
}
</style>
</head>
<body>
<div class="sitebox">
<img name="aerialmap" src="http://www.getmapping.com/sites/default/files/styles/post_image/public/quick_media/getmapping_aerialimagery_vertical_hamptoncourt_1_0.jpg?itok=tNmyWk21" usemap="#aerial2" style="border:5px solid #535353;">
<map name="aerial2">
<area shape="poly" coords="531,287,538,321,610,301,601,270" href="#" onclick="return false" title="building 1" data-image="https://placeholdit.imgix.net/~text?txtsize=40&bg=ff9900&txtclr=ffffff&txt=01&w=70&h=70">
<area shape="poly" coords="196,246,240,255,213,384,166,376" href="#" onclick="return false" title="Building 2" data-image="http://theinspirationgallery.com/D2-2020/mysticzon-titans.png">
</map>
</div>
<img id="image" src="" />
</body>
<script>
$("area").mousemove(function(e) {
$("#image").attr("src", $(this).data("image")).show().css({
left: e.pageX + 10,
top: e.pageY + 10
});
});
$("area").mouseout(function(e) {
$("#image").hide();
});
</script>
</html>


building 1 still shows a broken img but you get the idea i guess

This post was edited by MonsieurPorc on May 31 2020 06:19am
Member
Posts: 400
Joined: May 2 2018
Gold: 500.00
May 31 2020 01:24pm
MonsieurPorc, we are now cooking with fire !! I made a couple of small adjustments to your code:

1. Removed the class="sitebox" tag from the opening <div> as it was undefined. Doesn't seem to make a difference one way or another, so that's gone.

2. Replaced the image reference for "Building 1" "https://placeholdit.imgix.net/~text?txtsize=40&bg=ff9900&txtclr=ffffff&txt=01&w=70&h=70" and used a legit image reference.

3. Scrapped the whole aerial image and applied proper coordinates to my own image map.

Then I continued the pattern and added image popups for my zon's Titans, Griffs, Maras, Phoenix and Enigma. Since this is still in the testing stage, those are the only ones I did.

The end result can be seen here: http://theinspirationgallery.com/D2-2020/test2.html IT WORKS !!

I won't produce the code here because you can see how it all turned out by viewing the page source.

It doesn't look like much right now, but it's the closest I've come to achieving what I'm ultimately trying to do. Still have lots of things to figure out to make the popup images behave as they do in the game, but at least i've got a starting point now.

THANK YOU SO VERY, VERY MUCH for your help. Would not have made it this far without you, and I appreciate your time and consideration with my project. :hail:



Member
Posts: 28
Joined: Oct 23 2019
Gold: 0.00
May 31 2020 08:32pm
I was glad to help and I'm sure you will improve this to make it fit your needs!
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll