A popular technique for adding a little spice to your pages is
the Image Flip Mouseover. Using JavaScript, you can easily
install this effect in your pages.
Please keep in mind that as with most things beyond straight HTML, this will not work with all browsers. It should work with MSIE and Netscape provided each are Version 3 or greater. This tutorial will split the task into three ingredients:
Cut & Paste? Of course! Just be sure to cut from the screen and NOT from view source. Please try to get the script as shown working before making any changes. This can save you a little extra frustration! Instructions for customizing will be at the end of the tutorial. |
|
INGREDIENT #1: THE GRAPHIC FILES These are the graphics that we will be using in our tutorial script. The images with the B in their names are the ones displayed when the mouse passes over them. The ones without the letter B are displayed otherwise. Advice: It is very important to keep in mind that using this technique involves your reader downloading two graphics for each and every image flip link. You should therefore try and keep each image as small as possible. Always balance how long your reader has to wait vs. the value of the desired effect! In picking your graphics, make sure that your on/off set for any link are of the same exact height and width. This does not mean that all of your buttons have to be the same size, but each pair must be to avoid distortion. |
JOIN.GIF | JOINB.GIF | LOGON.GIF | LOGONB.GIF |
658 bytes | 2215 bytes | 791 bytes | 2291 bytes |
INGREDIENT #2: THE SCRIPT
This section contains our actual script source code. The script once modified for your needs should be pasted into the part of your page between the <HEAD> and </HEAD> tags. If your page already has these tags, do not include the <HEAD> and </HEAD> in the source below. In this page, the script is inserted directly under the page's <TITLE>. If you are uncertain as to where the <HEAD> and </HEAD> tags go, here is a quick reminder: <HTML> <HEAD> <TITLE>This is the title</TITLE> </HEAD> <BODY>HOW IT WORKS The script starts off by checking to see if you have a browser capable of running this script. If not, it will be ignored by the browser, otherwise, the script and extra images are loaded and will be ready for when the mouse passes over a script controlled link. When the mouse pointer passes over the image, the BNB_mouseon subroutine (mini-program) will display the image located in the section //MouseOn which if you notice, all have variable names ending with 1. i.e., login1 and login1.src All of the variable names ending with 0 are displayed when the mouse leaves the image. If this were not done, an image once selected, would forever remain selected. Okay, at least until you go to another page or turn off the computer. |
<HEAD> <script language="JavaScript"> <!-- browsok = (((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 3)) || ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion)>=3))); if(browsok){ // MouseOn // Note: the 88 is for the WIDTH, 25 is for the HEIGHT login1 = new Image(88, 25); login1.src = "LOGONB.GIF"; join1 = new Image(88, 25); join1.src = "JOINB.GIF"; // MouseOff // Note: the 88 is for the WIDTH, 25 is for the HEIGHT login0 = new Image(88, 25); login0.src = "LOGON.GIF"; join0 = new Image(88, 25); join0.src = "JOIN.GIF"; } function BNB_mouseon(n){ if(browsok){ imageON = eval(n + "1.src"); document [n].src = imageON; } } function BNB_mouseoff(n){ if(browsok){ imageOFF = eval(n + "0.src"); document [n].src = imageOFF; } } // --> </SCRIPT> </HEAD> |
INGREDIENT #3: THE LINKS
The final part step to installing our script is to place the links where we want them in our HTML document. Here are the key points about the links:
|
<a href="mouse.shtml" onmouseout="BNB_mouseoff('login')" onmouseover= "BNB_mouseon('login');return true "> <img src="LOGON.GIF" name="login" WIDTH=88 HEIGHT=25 VSPACE=3 border=0 alt=login></a> <a href="mouse.shtml" onmouseout="BNB_mouseoff('join')" onmouseover= "BNB_mouseon('join');return true "> <img src="JOIN.GIF" name="join" WIDTH=88 HEIGHT=25 VSPACE=3 border=0 alt=join></a> |
CUSTOMIZING THE SCRIPT FOR YOUR SITE
Once you have the the script working, you will know you have a working installation and can start making modifications. Here is all you have to do:
1. Select Your Graphics
Unless you make your graphics
that exact size, please measure your graphics and change the
values in every place they occur in the script and links. If you
do not do this, your graphics will be mushed and otherwise
distorted. Since this is an excercise in vanity, let's be fully
vain.
Keeping in mind that all the graphics will need to be downloaded
by your viewer, please try to keep each image as small as possible.
2. Add to the MouseOn List
mylink1 = new Image(88, 25); mylink1.src = "mypicb.gif";
3. Add to the MouseOff List
mylink0 = new Image(88, 25); mylink0.src = "mypic.gif";
4. Create Your Link
<a href="mouse.shtml" onmouseout="BNB_mouseoff('mylink')" onmouseover= "BNB_mouseon('mylink');return true "> <img src="mypic.gif" name="mylink" WIDTH=88 HEIGHT=25 VSPACE=3 border=0 alt=join></a> |