By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,282 Members | 1,518 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,282 IT Pros & Developers. It's quick & easy.

OnMouseOver and image maps working across multiple images

P: 31
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.
Oct 29 '09 #1
Share this Question
Share on Google+
13 Replies


gits
Expert Mod 5K+
P: 5,390
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
Oct 29 '09 #2

Dormilich
Expert Mod 5K+
P: 8,639
@seegoon
Iíd try to change the mouse pointer shape (hand), so that is represents a link.
Oct 29 '09 #3

P: 31
@Dormilich
It seems to do that anyway. But I think the problem still remains - it's not obvious enough in my eyes.
Oct 29 '09 #4

P: 31
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:

Expand|Select|Wrap|Line Numbers
  1. <script language="javascript">
  2.  
  3. Image1 = new Image(232,275)
  4. Image1.src = "images/hostage-cover.jpg"
  5.  
  6. Image2 = new Image(232,275)
  7. Image2.src = "images/hostage-cover-highlighted.jpg"
  8.  
  9. function highlight() {
  10. document.hostage.src = Image2.src; return true;
  11. }
  12.  
  13. function original() {
  14. document.hostage.src = Image1.src; return true;
  15. }
  16.  
  17. </script>
  18.  
Here's the code for the image:
Expand|Select|Wrap|Line Numbers
  1. <img 
  2. name="hostage" 
  3. src="images/hostage-cover.jpg" 
  4. width="232" 
  5. height="275" 
  6. alt="Hostage cover" 
  7. usemap="#hostage"/>
  8.  
And here's the image map code:
Expand|Select|Wrap|Line Numbers
  1. <map name="hostage" id="hostage">
  2.  
  3. <area    
  4. shape="poly"
  5.     coords="2,34,26,273,255,254,201,14"
  6.     href="http://books.mileskelly.net/menu1_sub1_detail.asp?ID=657"
  7.     title="Click here to find out more about Hostage"
  8.     onMouseOver="highlight()"
  9.     onMouseOut="original()"/>
  10.  
  11. </map>
  12.  
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!
Oct 29 '09 #5

Dormilich
Expert Mod 5K+
P: 8,639
@seegoon
then you need to treat two images in the highlight() code.
Oct 29 '09 #6

P: 31
@Dormilich
Sorry, I don't understand. Do you mean add another image to the highlight() in the script in the header? Thanks.
Oct 29 '09 #7

Dormilich
Expert Mod 5K+
P: 8,639
@seegoon
yupp, thatís what Iím talking about.
Oct 29 '09 #8

P: 31
@Dormilich
I've tried but I'm not getting it right. How should the code look? Thanks.
Oct 29 '09 #9

Dormilich
Expert Mod 5K+
P: 8,639
Expand|Select|Wrap|Line Numbers
  1. function highlight()
  2. {
  3.     img1.src = "picture1.jpeg";
  4.     img2.src = "picture2.jpeg";
  5. }
Oct 29 '09 #10

P: 31
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.
Oct 29 '09 #11

Dormilich
Expert Mod 5K+
P: 8,639
@seegoon
Iím a lazy bummer, did make some simplifications.

(why creating a whole new image if I only need the source path?)

@seegoon
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.
Oct 29 '09 #12

P: 31
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!
Oct 29 '09 #13

Dormilich
Expert Mod 5K+
P: 8,639
@seegoon
they indeed do, you're just not aware of it, because you wrap the .jpg in a global variable.
Expand|Select|Wrap|Line Numbers
  1. [global]
  2. Image1.src = "picture1.jpg"; // to keep the names simple
  3.  
  4. [global]
  5. function highlight() {
  6. [local]
  7.     // img1 is the <img> element in your HTML document
  8.     // Image1 is an JavaScript <img> object not attached anywhere
  9.     // JavaScript looks for Image1 in local scope => not found
  10.     // JavaScript looks for Image1 in global scope => found
  11.     // Image1.src = "picture1.jpg" (see above definition)
  12.  
  13.     // therefore
  14.     img1.src = Image1.src;
  15.     // is the same as
  16.     img1.src = "picture1.jpg";
  17.  
  18.     // do that also for the other image ...
  19. [local-end]
  20. }
  21. [global]
Oct 29 '09 #14

Post your reply

Sign in to post your reply or Sign up for a free account.