post your comment   print   send to a friend
Rate:   0% | Views: 188
Question categories:  Web Design

rollover images in website

Rollovers are really two images: the image when the mouse cursor is over the image area, and another when it's not. Javascript swaps between them when the mouse moves over (onMouseOver) and when it leaves being over (onMouseOut). Our example uses these two images:

First, copy the following JavaScript into your page. Copy it exactly as-as without making any changes.

<SCRIPT TYPE="text/javascript">
<!--
// copyright 1999 Idocs, Inc. http://www.idocs.com/tags/
// Distribute this script freely, but please keep this
// notice with the code.

var rollOverArr=new Array();
function setrollover(OverImgSrc,pageImageName)
{
if (! document.images)return;
if (pageImageName == null)
pageImageName = document.images[document.images.length-1].name;
rollOverArr[pageImageName]=new Object;
rollOverArr[pageImageName].overImg = new Image;
rollOverArr[pageImageName].overImg.src=OverImgSrc;
}

function rollover(pageImageName)
{
if (! document.images)return;
if (! rollOverArr[pageImageName])return;
if (! rollOverArr[pageImageName].outImg)
{
rollOverArr[pageImageName].outImg = new Image;
rollOverArr[pageImageName].outImg.src = document.images[pageImageName].src;
}
document.images[pageImageName].src=rollOverArr[pageImageName].overImg.src;
}

function rollout(pageImageName)
{
if (! document.images)return;
if (! rollOverArr[pageImageName])return;
document.images[pageImageName].src=rollOverArr[pageImageName].outImg.src;
}
//-->
</SCRIPT>

Then where you want the rollover you put this:

<A HREF="rollover_target.html"
onMouseOver = "rollover('home')"
onMouseOut = "rollout('home')"
><IMG
SRC="../graphics/home_out.gif"
NAME="home"
ALT="Home Page" BORDER=0
HEIGHT=130 WIDTH=115
></A>
<SCRIPT TYPE="text/javascript">
<!--
setrollover("../graphics/home_over.gif");
//-->
</SCRIPT>


Most of the code for these two tags is like normal links and images, but each of the tags have some extra information. <IMG SRC="..."> should be set the image to display when the mouse is not over.

The <A ...> tag has onMouseOver and onMouseOut attributes. onMouseOver calls the rollover() function, which sets the image for when the mouse is over. onMouseOut calls rollout(), which sets the image for when the mouse is not over. rollover() and rollout() each take one parameter: the name of the image. Note that the name of the image should be in single quotes.

The <IMG ...> tag has one extra attribute. We name the image with NAME="home". Each rollover on the page should have a unique name. The scripts use this unique name to refer to the image and change its properties as the mouse moves over and out.

Finally, we follow the <IMG ...> tag with a short JavaScript. The script has only one command: setrollover("../graphics/home_over.gif");. This command sets the source of the image to display when the mouse moves over the image. Note that the script should follow immediately after the <IMG ...> tag.

Customer Feedback
Rate:   0% | Views: 188 | Please Rate:  
 
If you have other comments or ideas for future technical tips, please type them here:

Email: (optional)

Comments: (optional)

 Domain Name Registration | Web Page Design    Back to serch results
Browse the Base
Knowledge Base
Web Design
  Trellix SiteBuilder
  FrontPage
  Professional Design
  Do It Yourself
  WSC Website Builder
Messages
 

Get Insider Info and Tips on the Aplus.Net Blog!

It's here! Introducing The Aplus.Net official blog. Check in as we run down the issues important to the web hosting industry, and offer tips and advice on how to make your website the best it can be. You can even post comments and suggest ideas. Get involved with the Aplus.Net community!
Visit the Aplus.Net Blog today!

Private Area
 
Ask
in Private
   
Personal
Folder
 
Related Questions
 
1. What exactly is HTML?
 
2. What about Hypertext Markup Language?
 
3. What is Body Tag?
 
4. How to place Headings on your page and how to use the Font Tags?
 
5. What is a HYPERLINK?
 
Home Browse Search Ask in Private Personal Folder   Help
powered by web hosting 
  Logged as: Guest