WebDeveloper.com �: Where Web Developers and Designers Learn How to Build Web Sites, Program in Java and JavaScript, and More!   
Web Developer Resource Directory WebDev Jobs
Animated GIFs
CSS
CSS Properties
Database
Design
Flash
HTML
HTML 4.01 Tags
JavaScript
.NET
PHP
Reference
Security
Site Management
Video
XML/RSS
WD Forums
 Client-Side
  Development

    HTML
    XML
    CSS
    Graphics
    JavaScript
    ASP
    Multimedia
    Web Video
    Accessibility
    Dreamweaver
    General
    Accessibility
    Dreamweaver
    Expression Web

    General

 Server-Side
  Development

    PHP
    Perl
    .NET
    Forum, Blog, Wiki & CMS
    SQL
    Java
    Others

 Site Management
    Domain Names
    Search Engines
    Website Reviews

 Web Development
  Business Issues

    Business Matters

 Etc.
    The Coffee Lounge
    Computer Issues
    Feedback




Beginners Guide to JavaScript (Part 5)

The OnMouseOver Event

These are your greatests friends when it comes to dynamic content. They allow pages to 'react' when a user runs a mouse over and off an object. Primarily used for 'image switching', these two event handlers can do everything. First, let's look at where these go. For the most part, any object can contain these two event handlers. Here, let's do the dreaded onMouseOver image switching. To start, we need to do a little planning. We need a function to do our image switching, yet we don't want to write a function for every switch we want to do. From experience, the easiest way we've found to do this is to pass in paramaters that will cover the name, file, and object of what we are trying to switch. Let's take a look at an example page. <HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">

var KeepVar;

function ChangePicture(Name)
{
KeepVar = Name;
SwitchImg = Name + "_on.gif";

document.images[Name].src=SwitchImg;
}

function Fix()
{
SwitchImg = KeepVar + "_off.gif";
document.images[KeepVar].src=SwitchImg;
}

</SCRIPT>
</HEAD>

<A HREF="." onMouseOver="ChangePicture('one')" onMouseOut="Fix()"<>IMG SRC="one_off.gif" NAME="one" BORDER=0></A>

<A HREF="." onMouseOver="ChangePicture('two')" onMouseOut="Fix()"><IMG SRC="two_off.gif" NAME="two" BORDER=0></A>

</BODY>
</HTML>



HTML5 Development Center


Recent Articles