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
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
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:
and then place the following code in the body of the page (wherever you want your image rollover to be).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>
You can see a working sample here.Code:<a href="#" onmouseout="m_out('navbutton1')" onmouseover="m_over('navbutton1')">[img]navbutton1-off.gif[/img]
Let me know how you get on! :o)
Paul
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
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
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