Welcome to Bucaro TecHelp!

Bucaro TecHelp
HTTPS Encryption not required because no account numbers or
personal information is ever requested or accepted by this site

About Bucaro TecHelp About BTH User Agreement User Agreement Privacy Policy Privacy Site Map Site Map Contact Bucaro TecHelp Contact RSS News Feeds News Feeds

Easy Java Script Rollovers

A rollover is when a user moves the mouse pointer over an image on a Web page the image is replaced with a new image. The simplest rollover can be created with the html code below.

<img name="rollover" src="out.gif"

This code responds to the browser's onMouseover and onMouseout events. it assumes that the images out.gif and over.gif are in the same directory as the html page containing the code. The images should be the same size.

This simple rollover has a minor problem. The second image is not downloaded from the server until the first time the user moves the mouse pointer over the first image. There would be some delay before the first image is replaced.

To make the second image appear immediately, you need to preload it. To preload images, assign them to Java Script Image objects in the HEAD section of your web page. This can be done using the code shown below.

<script language="JavaScript">
out = new Image;
over = new Image;

Then the rollover code in the body of the web page can get the images from the Java Script Image objects, as shown below.

<img name="rollover" src="out.gif"


The example rollover shown below could be used as a menu button. It uses three different images in response to four different mouse events. In this example, the rollover is used as a graphics link.

The code is shown below.

<script language="JavaScript">

out = new Image;
over = new Image;
down = new Image;

out.src = "out.gif";
over.src = "over.gif";
down.src = "down.gif"; 



<a alt="Rollover Code" target="top" href="rollcode.htm"

<img border="0" width="76" height="38" name="menu" src="out.gif"></a>


To use the example code on your own Web page, just copy the code from the popup window and paste it into your own Web page. Create yuor own images or right-click on each image below and select "save Picture As..." in the popup menu that appears.

Simple rollovers are extremely easy to create, however in order to avoid a delay in the appearance of the replacement image, you should preload the rollover images into Java Script Image objects in the HEAD section of your Web page.

More Java Script Code:
• HTML5 Canvas Storing and Clearing Transformations
• Java Script Code for Directory File List
• Date Picker For Your Web Site
• Code for Java Script Cylinder / Cone Volume Calculator
• A Brief Introduction to HTML for JavaScript Programmers
• JavaScript Code for Binary to Decimal - Decimal to Binary Conversion
• Round a Float to 4 Digits to the Right of the Decimal Point
• Calculators for Your Web Site : Loan Payment Calculator
• Creating Java Script Dynamic or anonymous Functions at Runtime
• JavaScript 24-Hour Trainer

RSS Feed RSS Feed

Follow Stephen Bucaro Follow @Stephen Bucaro

Fire HD
[Site User Agreement] [Privacy Policy] [Site map] [Search This Site] [Contact Form]
Copyright©2001-2023 Bucaro TecHelp 13771 N Fountain Hills Blvd Suite 114-248 Fountain Hills, AZ 85268