OnMouseOver and image maps working across multiple images | Newbie | | Join Date: Oct 2009
Posts: 8
| | |
Hi all.
So: I've put together a page, in which I want several clickable image maps. I've put those together already. The problem with image maps is that they're not very intuitive, so users don't really expect the image to be clickable and accordingly won't even try to. The solution is to have the image highlight whenever the mouse travels over the mapped-out area; I understand that this is quite easy. Some Googling has provided a few solutions.
However, my problem is this: because of the way the page was designed, some of the images themselves are split into separate jpegs; they were sliced up by the designer in Photoshop. What I need your help with is ascertaining whether it's possible to have one mouseover highlight two jpegs. To illustrate, one of the images is of a pig, foal, lamb and chick, with each one image mapped already. To get the required effect I understand that I can create four new images: one with each animal highlighted. Then I can get the image map to show the highlighted version with a tiny bit of scripting. But the pig's ear is cut off, and sits in a different jpeg. Could a mouseover of the 'pig map' in the large jpeg also prompt the ear - a different jpeg entirely - to change as well?
I'm not explaining this very well, I have to admit, but in principle it seems simple. If you need any further explanation I'll be sure to give it another go.
Thanks for reading regardless. If you got this far.
|  | Moderator | | Join Date: May 2007 Location: Munich, Germany
Posts: 4,134
| | | re: OnMouseOver and image maps working across multiple images
it is possible ... of course ... could you please post en example of the code you already have ... so that we have something to work with?
kind regards
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,648
| | | re: OnMouseOver and image maps working across multiple images Quote:
Originally Posted by seegoon The problem with image maps is that they're not very intuitive, so users don't really expect the image to be clickable and accordingly won't even try to. I’d try to change the mouse pointer shape (hand), so that is represents a link.
| | Newbie | | Join Date: Oct 2009
Posts: 8
| | | re: OnMouseOver and image maps working across multiple images Quote:
Originally Posted by Dormilich I’d try to change the mouse pointer shape (hand), so that is represents a link. It seems to do that anyway. But I think the problem still remains - it's not obvious enough in my eyes.
| | Newbie | | Join Date: Oct 2009
Posts: 8
| | | re: OnMouseOver and image maps working across multiple images
Here's a really stripped-down version of what I have at the moment, which should give a good impression. It works, but only on the one jpeg instead of across two.
Here's the Javascript in the header: -
<script language="javascript">
-
-
Image1 = new Image(232,275)
-
Image1.src = "images/hostage-cover.jpg"
-
-
Image2 = new Image(232,275)
-
Image2.src = "images/hostage-cover-highlighted.jpg"
-
-
function highlight() {
-
document.hostage.src = Image2.src; return true;
-
}
-
-
function original() {
-
document.hostage.src = Image1.src; return true;
-
}
-
-
</script>
-
Here's the code for the image: -
<img
-
name="hostage"
-
src="images/hostage-cover.jpg"
-
width="232"
-
height="275"
-
alt="Hostage cover"
-
usemap="#hostage"/>
-
And here's the image map code: -
<map name="hostage" id="hostage">
-
-
<area
-
shape="poly"
-
coords="2,34,26,273,255,254,201,14"
-
href="http://books.mileskelly.net/menu1_sub1_detail.asp?ID=657"
-
title="Click here to find out more about Hostage"
-
onMouseOver="highlight()"
-
onMouseOut="original()"/>
-
-
</map>
-
In case you're worried, Hostage is a novel! If there is any wasted code here, then please let me know and I'll glady destroy it.
Basically, what I want is for that mouseover to highlight two images instead of just one.
Thanks!
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,648
| | | re: OnMouseOver and image maps working across multiple images Quote:
Originally Posted by seegoon Basically, what I want is for that mouseover to highlight two images instead of just one. then you need to treat two images in the highlight() code.
| | Newbie | | Join Date: Oct 2009
Posts: 8
| | | re: OnMouseOver and image maps working across multiple images Quote:
Originally Posted by Dormilich then you need to treat two images in the highlight() code. Sorry, I don't understand. Do you mean add another image to the highlight() in the script in the header? Thanks.
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,648
| | | re: OnMouseOver and image maps working across multiple images Quote:
Originally Posted by seegoon Do you mean add another image to the highlight() in the script in the header? yupp, that’s what I’m talking about.
| | Newbie | | Join Date: Oct 2009
Posts: 8
| | | re: OnMouseOver and image maps working across multiple images Quote:
Originally Posted by Dormilich yupp, that’s what I’m talking about. I've tried but I'm not getting it right. How should the code look? Thanks.
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,648
| | | re: OnMouseOver and image maps working across multiple images - function highlight()
-
{
-
img1.src = "picture1.jpeg";
-
img2.src = "picture2.jpeg";
-
}
| | Newbie | | Join Date: Oct 2009
Posts: 8
| | | re: OnMouseOver and image maps working across multiple images
Sorry, still not working for me. That code looks very different to what it was before; there was no .jpg mentioned in the original, for instance. Should I be changing something else too? Thanks for your time, I know this must be boring for you.
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,648
| | | re: OnMouseOver and image maps working across multiple images Quote:
Originally Posted by seegoon That code looks very different to what it was before; I’m a lazy bummer, did make some simplifications.
(why creating a whole new image if I only need the source path?) Quote:
Originally Posted by seegoon there was no .jpg mentioned in the original, for instance. uh? what about lines 4/7 in post #5, ain’t that no jpegs?*
* even if it were so, it wouldn’t matter because the <img>'s src attribute is always an URI.
| | Newbie | | Join Date: Oct 2009
Posts: 8
| | | re: OnMouseOver and image maps working across multiple images
Sorry, I've been a bit unclear; I meant that the function highlight() didn't contain any .jpgs. Anyway, I've been struggling with this all day and have come to the conclusion that I've bitten off more than I can chew! What I want to achieve looks to be seriously complicated beyond what I had realised and I only really understand CSS and HTML. I'm trying to do something that no tutorials seem to actually explain; not only do I want what I've said above, I want several of them on one page. This is just a bit beyond me, and I need to get my nose into a big ol' tutorial or book to start learning a bit of JS. But thank you for your help - it's steered me in the right direction at least!
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,648
| | | re: OnMouseOver and image maps working across multiple images Quote:
Originally Posted by seegoon Sorry, I've been a bit unclear; I meant that the function highlight() didn't contain any .jpgs. they indeed do, you're just not aware of it, because you wrap the .jpg in a global variable. - [global]
-
Image1.src = "picture1.jpg"; // to keep the names simple
-
-
[global]
-
function highlight() {
-
[local]
-
// img1 is the <img> element in your HTML document
-
// Image1 is an JavaScript <img> object not attached anywhere
-
// JavaScript looks for Image1 in local scope => not found
-
// JavaScript looks for Image1 in global scope => found
-
// Image1.src = "picture1.jpg" (see above definition)
-
-
// therefore
-
img1.src = Image1.src;
-
// is the same as
-
img1.src = "picture1.jpg";
-
-
// do that also for the other image ...
-
[local-end]
-
}
-
[global]
|  | Similar JavaScript / Ajax / DHTML bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,411 network members.
|