AllExperts > DHTML 
Search      
DHTML
Volunteer
Answers to thousands of questions
 Home · More DHTML Questions · Answer Library  · Encyclopedia ·
More DHTML Answers
Question Library

Ask a question about DHTML
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Andrew Hoffman
Expertise
I can field just about any question within this topic ranging from JavaScript to CSS, the two ingredients of DHTML. I`m very interested in the W3C and its validation rules for HTML, XHTML, and CSS, and enjoy answering questions of this type as well. I detest sleep and respond at all hours of the day or night.


Experience
Experience in the area
I've been working with DHTML and CSS for 7 years now and build/maintain websites of my own that implement DHTML navigation.

What I'm doing now
My contract with Microsoft has ended and I am working for myself once again. Please contact me for any front-end work at antibland@gmail.com

 
   

You are here:  Experts > Computing/Technology > HTML/XML > DHTML > Question for Andrew

DHTML - Question for Andrew


Expert: Andrew Hoffman - 6/21/2009

Question
Hi Andrew:
I was wondering if you could help me. Firstly, thank you so much for all the information at allexperts.com.
It has come in amazingly handy and has helped so much and in fact I think I may have sent you this question before, so if I did please forgive me.

My question is a javascript coding question that I am absolutely desperate for an answer for.

I have a two images, image1.gif and image2.gif. When you roll over image1.gif it becomes newimage1.gif and image2.gif becomes newimage2.gif. So you roll over one and both change. No problem there. The only other thing I want to do is to get one of the new images - newimage2.gif - to be an image map.

The code I have now is:

<head>
<SCRIPT language="JavaScript">
<!--

   if (document.images) {
       pic1on = new Image(226, 93);
       pic1on.src = "images/newimage1.gif";
       pic2on = new Image(684, 296);
       pic2on.src = "images/newimage2.gif";
   }

   function lightup(imgName, imgName2) {
       if (document.images) {
           imgOn = eval(imgName + "on.src");
           document[imgName].src = imgOn;
           imgOn2 = eval(imgName2 + "on.src");
           document[imgName2].src = imgOn2;
       }
   }

   
//-->
</SCRIPT>
</head>
<body>
<A HREF="" onMouseover="lightup('pic1','pic2')"><IMG SRC="images/image1.gif" name="pic1" width="226" height="93" border="0"></A>
<br>
<img src="images/image2.gif" name="pic2" width="684" height="296" border="0">
</BODY>


Do you know what I would have to add to the code to make this happen?

If you have any idea and would be able to provide me with the information it would be GREATLY, GREATLY appreciated. Again, I am desperate.

Thank you for listening and thank you again for all the good work you do.

Sincerely,

Ari Strauch

Answer
Hi Ari,

I don't think you're that close to success going this way.  Please try this out instead: http://www.alistapart.com/articles/sprites/

This is the way images maps are done today.  The nice thing is that, using only CSS, we have total control over the map 'slices' using small, absolutely positioned links to represent each slice.  It will take you about 20 minutes to learn this method, but it's much more sustainable then using this clunky JavaScript approach.  The nicest thing is that you won't need JavaScript at all for this.

Here's a the crux of the article:

"Specifically, we’re going to replace old-school image slicing and dicing (and the necessary JavaScript) with a CSS solution. And because of the way CSS works, we’re going to take it further: by building a grid of images and devising a way to get each individual cell out of the grid, we can store all buttons/navigation items/whatever we wish in a single master image file, along with the associated “before” and “after” link states."

If you have problems when implementing this approach, please write and I'll help you along.

Andrew

Add to this Answer   Ask a Question


 
User Agreement | Privacy Policy | Kids' Privacy Policy | Help
Copyright  © 2008 About, Inc. AllExperts, AllExperts.com, and About.com are registered trademarks of About, Inc. All rights reserved.