spacer

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

home / experts / dhtml / column2
Developer News
Mandrake Linux Founder Back, Virtually
Amazon: We're a Technology Company
Sun Expands MySQL With Closed Source
Logo

One Image Rollover:
clipping the background color on the fly

Many rollovers presently in use on the web use a second image with just a highlight color. With Dynamic HTML, we can achieve this effect without the second image:

Pass your mouse over the menu below:

Here we are clipping a solid color element. This color is the element's background color. No second image is required.

This very simple effect is similar in most details to our 2 image rollover previously discussed. We use exactly the same clipping method. There are, however, two minor but important changes:

Step by Step

Declare the CSS elements. elMenuBG takes the place of elMenuOver from the previous example. This element is just one solid color assigned by the value of the background-color property. In the stylesheet, therefore, define both the clip property and the background-color property.

BUG Note: Netscape, presently, has a well-documented CSS background-color inheritance bug. We therefore use the proprietary CSS property layer-background-color. Explorer will ignore it.

<HEAD> . . . <STYLE TYPE="text/css"> <!-- #elMenu { position: relative } #elMenuBG { position: absolute; top: 0; left: 0 clip: rect(0 468 18 0); background-color: #DDDDDD; layer-background-color: #DDDDDD } #elMenuIMG { position: absolute; top: 0; left: 0 } --> </STYLE>

Our JavaScript does not need the string variables we used before, since elMenuBG is, by definition, blank and will not be rendered by older browsers;
Our array remains the same; and mapOver is redefined to clip elMenuBG.

Our script becomes:

Our <BODY> HTML is completely backward compatible because elMenuBG is an empty element. Remember it must preceed our image in the page. Our MAP remains the same.

<DIV ID="elMenu"> <DIV ID="elMenuBG"></DIV> <DIV ID="elMenuIMG"> <IMG SRC="menu.gif" USEMAP="#mpMenu" WIDTH=468 HEIGHT=18 BORDER=0> </DIV> </DIV> . . . <MAP NAME="mpMenu"> <AREA SHAPE="RECT" COORDS="0,0 116,18" HREF="/" onMouseOver="mapOver(1,true)" onMouseOut="mapOver(1,false)"> <AREA SHAPE="RECT" COORDS="117,0 181,18" HREF="/cgi-bin/suggest.cgi" onMouseOver="mapOver(2,true)" onMouseOut="mapOver(2,false)"> <AREA SHAPE="RECT" COORDS="182,0 222,18" HREF="http://www.coolcentral.com" onMouseOver="mapOver(3,true)" onMouseOut="mapOver(3,false)"> <AREA SHAPE="RECT" COORDS="223,0 263,18" HREF="/new/" onMouseOver="mapOver(4,true)" onMouseOut="mapOver(4,false)"> <AREA SHAPE="RECT" COORDS="264,0 339,18" HREF="/headlines/" onMouseOver="mapOver(5,true)" onMouseOut="mapOver(5,false)"> <AREA SHAPE="RECT" COORDS="340,0 397,18" HREF="/search.cgi" onMouseOver="mapOver(6,true)" onMouseOut="mapOver(6,false)"> <AREA SHAPE="RECT" COORDS="398,0 468,18" HREF="/index2.html" onMouseOver="mapOver(7,true)" onMouseOut="mapOver(7,false)"> </MAP>

And now, a Rollover with 0 (zero) Images

This one is up to you. Try using what we have discussed to create a text-based rollover. Send it to us. If it works, we'll mention it in a future column.

HINT: The next page may give you some ideas.

Produced by Peter Belesis and

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

webref The latest from WebReference.com Browse >
Working with the DOM Stylesheets Collection · Administering RBAC in PHP 5 CMS Framework · xref: Automatic Cross Referencing Script
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Combine BottomCount() with Other MDX Functions to Add Sophistication · Creating a Daemon with Python · The Coming Voice-over-WiMAX Revolution

All Rights Reserved. Legal Notices.
Created: 08/06/97
Revised: 10/16/97

URL: http://www.webreference.com/dhtml/column2/bgcolor.html