Submit Your Article Forum Rules

Results 1 to 6 of 6

Thread: Hover Images

  1. #1
    Senior Member
    Join Date
    Jul 2003
    Posts
    107

    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

  2. #2
    Senior Member paulhiles's Avatar
    Join Date
    Jul 2003
    Posts
    2,073
    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

  3. #3
    Senior Member
    Join Date
    Jul 2003
    Posts
    107
    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

  4. #4
    Senior Member
    Join Date
    Jul 2003
    Posts
    107
    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

  5. #5
    Senior Member paulhiles's Avatar
    Join Date
    Jul 2003
    Posts
    2,073
    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.

  6. #6
    Senior Member
    Join Date
    Jul 2003
    Posts
    107
    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

Similar Threads

  1. Whatever:Hover doesn't work in IE7
    By trancehead in forum Graphics & Design Discussion Forum
    Replies: 8
    Last Post: 11-12-2008, 07:32 PM
  2. IE Hover
    By PARoss in forum Web Programming Discussion Forum
    Replies: 10
    Last Post: 05-18-2007, 04:37 AM
  3. Hover over Images
    By JuniorOnline in forum Web Programming Discussion Forum
    Replies: 2
    Last Post: 03-30-2006, 07:42 AM
  4. CSS HOVER-IE
    By candlese in forum Graphics & Design Discussion Forum
    Replies: 3
    Last Post: 12-10-2005, 09:17 AM
  5. CSS hover links
    By justinw in forum Graphics & Design Discussion Forum
    Replies: 9
    Last Post: 03-20-2004, 02:48 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •