WebProWorld Part of WebProNews.com
Page One Link To Us Edit Profile Private Messages Archives FAQ RSS Feeds  
 

Go Back   WebProWorld > Site Design > Graphics & Design Discussion Forum
Subscribe to the Newsletter FREE!


Register FAQ Members List Calendar Arcade Chatbox Mark Forums Read

Graphics & Design Discussion Forum Post your graphics design questions/comments/ideas in here. Ask questions, post tutorials, discuss trends and best practices. Sub-forum for website accessibility and usability.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-18-2004, 01:05 AM
WebProWorld Pro
 

Join Date: Jul 2003
Location: United States of America
Posts: 137
WiseWizards RepRank 0
Default Hover Images

Hello!

How can I create an image that changes on hover? I've tried one script at LissaExplains.com, but it didn't seem to work. Could someone please give me their code?

Thanks,
Mike
__________________
Wise WizardsŪ Website Design :: Professionally Designed Websites at Affordable Prices
Reply With Quote
  #2 (permalink)  
Old 06-18-2004, 10:12 AM
paulhiles's Avatar
WebProWorld 1,000+ Club
 

Join Date: Jul 2003
Location: UK
Posts: 2,803
paulhiles RepRank 0
Default

Lots and lots of ways to do this! You can use CSS rollovers if you feel like being adventurous. If you're just after a straightforward Javascript example.. here's one that I've used in the past. Obviously, you're going to need two images.. one will be your "hover" image, the other your regular image that will be there initially and "onmouseout".

Place this first bit of code in the <head> of your page:

Code:
<script language="javascript" type="text/javascript">
<!--
  if (document.images)
   {
     navbutton1on= new Image(put-your-imagewidth-here,your-image-height);
     navbutton1on.src="navbutton1-over.gif";

     navbutton1off= new Image(your-image-width,your-image-height);
     navbutton1off.src="navbutton1-off.gif";
   }

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

function m_out(imgName)
 {
   if (document.images)
    {
      imgOff=eval(imgName + "off.src");
      document[imgName].src= imgOff;
    }
 }
//-->
</script>
and then place the following code in the body of the page (wherever you want your image rollover to be).
Code:
<a href="#" onmouseout="m_out('navbutton1')" onmouseover="m_over('navbutton1')">[img]navbutton1-off.gif[/img]
You can see a working sample here.
Let me know how you get on! :o)

Paul
Reply With Quote
  #3 (permalink)  
Old 06-18-2004, 05:32 PM
WebProWorld Pro
 

Join Date: Jul 2003
Location: United States of America
Posts: 137
WiseWizards RepRank 0
Default

Thanks, that's exactly what I wanted. I'll try it out ASAP!

Thanks,
Mike

P.S. Do I just substitute my image info into the HEAD script only, or do I also substitute the image into the BODY script?
__________________
Wise WizardsŪ Website Design :: Professionally Designed Websites at Affordable Prices
Reply With Quote
  #4 (permalink)  
Old 06-18-2004, 05:54 PM
WebProWorld Pro
 

Join Date: Jul 2003
Location: United States of America
Posts: 137
WiseWizards RepRank 0
Default

What if I want more than one button? Do I have to copy both scripts in as many times as I have buttons?

Regards,
Mike
__________________
Wise WizardsŪ Website Design :: Professionally Designed Websites at Affordable Prices
Reply With Quote
  #5 (permalink)  
Old 06-18-2004, 08:43 PM
paulhiles's Avatar
WebProWorld 1,000+ Club
 

Join Date: Jul 2003
Location: UK
Posts: 2,803
paulhiles RepRank 0
Default

The sample page I included in my post here for cyberious is still available.. you can check that out. Basically you just add further definitions for each of your rollover images.

Remember, this isn't the only method.. it's always good to try out a few variations with something like this.
Reply With Quote
  #6 (permalink)  
Old 06-19-2004, 01:09 AM
WebProWorld Pro
 

Join Date: Jul 2003
Location: United States of America
Posts: 137
WiseWizards RepRank 0
Default

Thanks, I'll try out some new ways and find the one that's best for me.

Regards,
Mike
__________________
Wise WizardsŪ Website Design :: Professionally Designed Websites at Affordable Prices
Reply With Quote
Reply

  WebProWorld > Site Design > Graphics & Design Discussion Forum
Tags: ,



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Search Engine Optimization by vBSEO 3.2.0