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 provided in this article.
Welcome to Bucaro TecHelp!

Welcome to Bucaro TecHelp!
Maintain Your Computer and Use it More Effectively
to Design a Web Site and Make Money on the Web

[About BTH]  [User Agreement]  [Privacy Policy]  [Site Map]  [Contact Form]  [Advertise on BTH]  [News Feed]

Google
Web
This Site

Easy 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"
onMouseover="document.images.rollover.src="over.gif"
onMouseout="document.images.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.

<head>
<script language="JavaScript">
out = new Image;
over = new Image;
out.src="out.gif";
over.src="over.gif";
</script>
</head>

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

<body> 
<img name="rollover" src="out.gif"
onMouseover="document.rollover.src=over.src"
onMouseout="document.rollover.src=out.src">

</body>

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.

<html>
<head>
<script language="JavaScript">

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

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

</script>

</head>
<body>

<a alt="Rollover Code" target="top" href="rollcode.htm"
onMouseover="document.menu.src=over.src" 
onMouseout="document.menu.src=out.src"
onMousedown="document.menu.src=down.src"
onMouseup="document.menu.src=over.src">

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

</body>
</html>

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.

Web Design Sections

RSS Feed RSS Feed

Easy Java Script Code
Easy Java Script Windows
Easy Rollovers
Easy Picture Transition Effects
Easy Moving Popup Code
Easy Slide Show Code
Easy Slide Show Code With Linked Slides
Slide Show with Different Size Images
Easy Picture Zoom Code
Easy Picture Panning Code
Easy Java Script Animation
Easy JavaScript Picture Selector Code
Easy Animated Banners with Java Script
Easy Java Script Form Validation
Easy Drag n Drop Code
Easy Graph Generating Code
Easy Code to Sort a Table by Column
Easy Fading Text Banner Code
Easy Expanding Banner Code
Calendars for Your Website
Date Picker For Your Web Site
Calculators For Your Web Site
Loan Payment Calculator
Length Units Converter
Body Mass Index
Fahrenheit to Celsius Converter
Decimal to Hexidecimal Converter
Easy Code for Screen Tape Adding Machine
Code for Java Script Circle⁄Sphere Calculator
Round a Float to 4 Digits to the Right of the Decimal Point
Make Your Own Graphical Digital Clock
Let Your Web site Visitors Set Font Size
How to Disable the Browser Back Button
Add More Bang to Your Content With Keyword Popup Menus
Put a Music Off Switch on Your Webpage
Java Script Random Password Generator
Password Protection Using Java Script
Replace Drop-down with Drag-and-drop
Submit Forms Without CGI
Code for a Less annoying Popup Window
Using the Java Script Array Object
Using the Java Script Date Object
Java Script Message Boxes
How to Shuffle the Deck With Java Script
Web Site Menus : Which Section Am I In?
How Far Did the User Scroll?
Where Did the User Click?
Four Ways to Use Java Script Event Handlers
Create Your Own Database Using Only Notepad : CDV

[Site User Agreement]  [Advertise on This site]  [Search This Site]  [Contact Form]
Copyright©2001-2007 Bucaro TecHelp P.O.Box 18952 Fountain Hills, AZ 85269