Ryan's District
November 22, 2008, 06:08:08 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Ryan's District Lottery: Claim your ticket or check
Jackpot details  
 
   Home   Help Search Chat Calendar Chess Shop Login Register  
Digg This!
Pages: [1]   Go Down
  Send this topic  |  Print  
Author Topic: JavaScript image rollovers  (Read 3681 times)
0 Members and 1 Guest are viewing this topic.
ben2ong2
Quality Poster
Paid
Hero Member
*****

Reputation: 17
Offline Offline

Gender: Male
Posts: 2374
9976.80 RD$

View Inventory
Send Money to ben2ong2

View Profile Awards
« on: October 04, 2006, 03:01:59 AM »


JavaScript image rollovers have been one of the most used features for bringing interactivity to web pages. They refer to the change in the image when the mouse cursor is moved over and subsequently off the image.

Rollovers employ two JavaScript event handlers. onmouseover, that captures the action when the mouse cursor is brought over an image and onmouseout, that detects the action when the mouse cursor is moved off an image. These two even handlers are placed inside the anchor tag that surrounds the IMG tag.

We also use the src property of the JavaScript image object. This property refers to the file name of the image being displayed (image source). Finally, we employ the NAME attribute of the HTML IMG tag to explicitly refer to the image in question.

The logic is extremely simple. It's a matter of changing the image when the mouse cursor is placed over it and then changing it back to the original when the mouse cursor moves off the image.

Let's construct our image tag:

<IMG SRC="moveup.gif" WIDTH="143" HEIGHT="39" BORDER="0"
ALT="Move your mouse over me" NAME="sub_but">
Note: We use the NAME attribute of the HTML IMG tag to give the name sub_but to our image. JavaScript event handlers will refer to the image with this name.
You'll notice that the image source (file name) is moveup.gif, which is the image to be displayed when the mouse cursor is off the image.

Now, we place anchor tags around this image:

<A HREF="somewhere.html">
<IMG SRC="moveup.gif" WIDTH="143" HEIGHT="39" BORDER="0"
ALT="Move your mouse over me" NAME="sub_but">
[/url]


Lastly, we include the two JavaScript event handlers inside this anchor tag.

<A HREF="somewhere.html"
onmouseover="document.sub_but.src='movedown.gif'"
onmouseout="document.sub_but.src='moveup.gif'">

<IMG SRC="moveup.gif" WIDTH="143" HEIGHT="39" BORDER="0"
ALT="Move your mouse over me" NAME="sub_but">

[/url]
Remember that the image object is a part of the document object and its src property refers to the file name of the image being displayed.
onmouseover specifies that the source (src) of sub_but (the name of our image) should change to movedown.gif when the mouse cursor is moved over the image. When the mouse cursor is moved off the image, its source should be changed back to moveup.gif.
You'll note that the JavaScript code is written right inside the anchor tags. This is fine for one or two image rollovers. However, if you plan for several image rollovers on a page, it is advisable to place this JavaScript code into functions.
Let's see how this is done.



Logged

You are not allowed to view links.
Register or Login
Free Paid Survey & Home Business Resources.

You are not allowed to view links.
Register or Login
Free Article Directory | Quality Content
Ryan's District
« on: October 04, 2006, 03:01:59 AM »

 Logged
Pages: [1]   Go Up
  Send this topic  |  Print  
 
Jump to:  

Archive - WAP2 - WAP - imode
Sponsors: RAYAN.tv
-

Powered by MySQL Powered by PHP Powered by SMF 1.1.7 | SMF © 2006-2008, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.199 seconds with 30 queries.

Google visited last this page November 20, 2008, 04:38:59 PM