spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / programming / javascript / domscripting / 1 To page 1To page 2To page 3To page 4current pageTo page 6To page 7
[previous][next]
Developer News
Mandrake Linux Founder Back, Virtually
Amazon: We're a Technology Company
Sun Expands MySQL With Closed Source

Scripting for 5th Generation Browsers and Beyond

Four State DOM Rollovers with a Single Image

Remember that earlier I stated that the setAttribute() method allows for the setting of any attribute such as width and height? Well, let's use these attributes to create a four state rollover with just a few lines of code and a single image. First the image tag:

<img src="button_eddie.png" id="Image1" border="0" 
     width="25'" height="25'">

As noted previously, what is important in the above tag is to set a unique id for the image so that we can later retrieve the image element via the document.getElementById() method. The rollover script we employ to put this into action is as follows: (live example)

<script language="JavaScript" type="text/javascript">
function rollOvers(id, new_width, new_height) {
document.getElementById(id).setAttribute('width', new_width);
document.getElementById(id).setAttribute('height', new_height);
 }
</script>

In this example, we utilize three arguments, id, new_width and new_height. The id argument is used to retrieve the unique id of the image, in this instance image1, and the new_width and new_height arguments will be used from the event handler to set new image dimensions.

<a href="#" onClick="rollOvers('Image1','28','28')" 
            onMouseOver="rollOvers('Image1','26','26')" 
            onMouseOut="rollOvers('Image1','24','24') ">

Let's consider what is occurring here for a moment. We have enabled four image dimensions for a single image. Effectively, we have produced a four state disjointed rollover. The four states are:

  1. The initial dimensions of 25*25.
  2. The onMouseOver dimensions of 26*26.
  3. The onMouseOut dimensions of 24*24.
  4. The onClick dimensions of 28*28.

Netscape Rollover Fix

Before you all start screaming at me with complaints that rollovers don't work properly in Netscape 6 because of a refresh bug, let me make the point that the thing with Web development is to find solutions to these types of problems wherever possible. Sometimes no solution exists and as Web developers we have to wear that, but on many occasions solutions do exist, provided we start to think out of the box. Luckily, such a solution exists for the Netscape 6 refresh bug and rollovers.

To fix the rollover problem in Netscape 6 two things need to occur.

Use a timer to force the rollovers, e.g.

function forceIt(){
   setTimeout("swapImage()",1);
}

and to fix the refresh bug use onResize="history.go(0)" in the body tag. Note that this fix doesn't apply to Netscape 6.1+ or Mozilla builds after 0.8.

Contents:

home / programming / javascript / domscripting / 1 To page 1To page 2To page 3To page 4current pageTo page 6To page 7
[previous][next]

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Whitepapers and eBooks

Symantec Whitepaper: Converging System and Data Protection for Complete Disaster Recovery
Intel Whitepaper: Comparing Two- and Four-Socket Platforms for Server Virtualization
IBM Solutions Brief: Go Green With IBM System xTM And Intel
HP eBook: Simplifying SQL Server Management
IBM Contest: Are You the Next Superstar? Join the "Search for the XML Superstar" Contest to Find Out
Intel PDF: Quad-Core Impacts More Than the Data Center
Intel PDF: Virtualization Delivers Data Center Efficiency
Go Parallel Article: PDC 2008 in Review
Avaya Article: Communication-Enabled Mashups: Empowering Both Business Owners and IT
Intel Whitepaper: Building a Real-World Model to Assess Virtualization Platforms
PDF: Intel Centrino Duo Processor Technology with Intel Core2 Duo Processor
Microsoft Article: Build and Run Virtual Machines with Hyper-V Server 2008
  Go Parallel Article: Q&A with a TBB Junkie
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
IBM eBook: The Pros and Cons of Outsourcing
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
Symantec Whitepaper: Comprehensive Backup and Recovery of VMware Virtual Infrastructure
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP · Working with the DOM Stylesheets Collection
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Fixing MySQL Replication · Firewall Guide: First Steps to Securing the Enterprise · VoxOx Tames the Tumultuous Communications Tangle


Created: August 16, 2001
Revised: August 16, 2001


URL: http://webreference.com/programming/javascript/domscripting/1/5.html