///A Simple Image/Link Rollover in Javascript

A Simple Image/Link Rollover in Javascript

Image/Link Rollover in Javascript

Your web site has been up and running for some time and while you are pleased with the results, you can’t help but think that it needs a little bit more “something”.

Maybe a tweak or two to make it stand out a little more. Nothing flashy or too complicated.

Maybe you want to do something with the links, like add some pictures or a “rollover effect”. Well, maybe not all the links; just one or two. There’s a fine line between classy and gaudy.

The problem is: you know nothing about Javascript. To you and a lot of people Javascript looks like ancient Vulcan. And yet there is a solution. Cut and paste comes to mind.

Just head on over to your friendly free Java source, find what you need and cut and paste it into your web page. Sounds simple enough. BUT. As the universe has shown us time and time again…nothing is simple.

Now a couple of hours have passed and you still haven’t found what you were looking for. It seems the Java codes you have been looking at, all deal with muliple images and a humoungus amount of code to place in the “head section” and nowhere does it give you instructions as to how to make the rest of the Java code fit into your web page. Forget about where you want to put it.

Believe it or not, there is a small compact Javascript that you can paste into your web page and put it where you want it. And the added bonus is: it’s a image link.

You will need three pictures in gif, jpg or bmp: your choice. Two of the three pictures must be the same.

Now here’s the Javascript:


Step one: Paste this code into the Head section of your HTML of your document.



{!– Hide Script function move_in(img_name,img_src) { document[img_name].src=img_src; }

function move_out(img_name,img_src) { document[img_name].src=img_src; }

//End Hide Script–}



Step two: Paste this code into the Body of your Html document


{a href=”anylink.html



<img src=”image_out.gif”>

<alt=”Move your mouse over here!” name=”image1″>

< /a>



Now look down under the “body” tag and you will see: OnMouseOver=”move_in(‘image1′,’image_on.gif’)”. Image_on.gif is the picture you want displayed. Image_out is what will be seen when you roll your mouse over the image.

So far that’s two images. The final image will go into the last peice of code which is “image_out.gif”. This should be your copy image. You can also change the information in the “alt” tag to whatever you like. Place any link you want in the “link” tag.

This little peice of Javascript code makes a great preview picture link for whatever site you want to link it to. Have fun with this. Experiment with different images or just use text and an image. It’s very versatile. I think it works best in tables and should be most effective in getting some attention for you web pages.

2010-05-25T22:54:08+00:00 October 31st, 2007|JavaScript|0 Comments

About the Author:

Because of ProfitLance Ben has learned to write over 16 articles (and counting), start a blog and build his own websites from scratch.

Leave A Comment