Home > Articles > Web Design & Development > HTML/CSS

  • Print
  • + Share This
This chapter is from the book

This chapter is from the book

RevealTrans Filter

First Things First: This is a DHTML event; thus you must be running MSIE4.0+ to see the effect. However, browsers that do not understand DHTML will happily ignore the commands without throwing errors, so feel free to use them at will.

You can find this tutorial, and all of its examples, online at http://www.htmlgoodies.com/beyond/revealTransFilter.html
You can download just the examples at http://www.htmlgoodies.com/wpg/.

Do you want a cool effect? Dig this! Figure 3.4 shows what this tutorial teaches you. Notice that the button says to click it for the image to go away. I clicked it and then captured the image as the image was disappearing. Inside of two seconds, it was gone. Really!

Figure 3.4Figure 3.4 No eggs, thanks...

Better yet, you can also set it so that the image comes back.

What you're seeing there is the revealTrans() filter at work. Two separate JavaScripts are using the filter to make a SPAN disappear and then reappear. I'll show you the first one and then explain the second one, but only quickly. (It's just like the first one only backward.)

Make It Disappear

As I said previously, the image, "eggs.gif", itself doesn't disappear. The SPAN surrounding the image disappears. The image just goes with it. So, let's start with the SPAN and its image. The code looks like this:

<INPUT TYPE="button" VALUE="Go Away!" onClick="go();">
<SPAN ID=Egg1 Style="Visibility:visible;
<IMG SRC="eggs.gif">

The first line is a form button with the text "Go Away!" The button is there to act as a trigger for the function "go()". When clicked, the function fires.

The code is a basic SPAN surrounding the image flag displaying the eggs.gif. A NAME, Egg1, is given to the SPAN. That links it to the next JavaScript covered in the next paragraph. Also, inside the SPAN are some Style Sheet commands and the filter. Note that the visibility of the SPAN is set to "visible". That changes in the next script. Then comes the Filter:revealTrans(duration=2). You can probably guess that the 2 means two seconds for the effect. Then the height and width of the image are given so that the SPAN fits it perfectly.

Okay. Got the SPAN? Good. Now here is the script that does the dirty work:

<SCRIPT LANGUAGE="javascript">
function go() { 
if (Egg1.style.visibility == "visible") 
Egg1.style.visibility = "hidden"; 
Egg1.style.visibility = "visible"; 

The script is pretty straightforward. When the function go() is triggered, the filter in Egg1 is applied. Remember that Egg1 is the SPAN. We gave it that name in the first script.

Then, if Egg1 is visible, set its value to "hidden" using transition number 12. Otherwise, make the SPAN Egg1 visible by using transition number 12.

Then play the transition! There's nothing to it!

Transition Numbers

There are 22 different transitions to choose from. There is also transition 23, which chooses a number at random. I just happen to like 12.

And no, you do not need both transitions set to 12. It can be two different numbers. Table 3.1 describes the magic 23 numbers.

Table 3.1 Transition Effects


What Happens


Reveals from inside out


Scrolls in from outer parts


Scrolls out from the center


Scrolls up from the button


Scrolls down from the top


Scrolls left to the right


Scrolls right to the left


Displays vertical blinds left to right


Displays horizontal blinds top to bottom


Displays a combination of 8 and 9


Looks a lot like 8


Comes in, in pixels


Scrolls in from outer parts


Scrolls out from the center


Closes from both the top and bottom


Opens from center to top and bottom


Displays a diagonal roll from right to left


Displays a different angle diagonal roll right to left


Displays number 17 the other way


Displays number 18 the other way


Displays random horizontal lines


Displays random vertical lines


Displays completely random

After Transition 23, the cycle of effects appears to start over. Any one will work just fine. Some are just more interesting than others.

Make It Go Away

There are really two things to discuss when it comes to reversing the effect: simply setting the current script to go the opposite way and putting a second revealTrans() on a page.

If all you want to do is make the script and SPAN previously noted to go from invisible to visible, it's simple. Everywhere you see the word "visible", you change it to "hidden"; and everywhere you see the word "hidden", you change it to "visible". Don't forget to change the instance in the SPAN as well.

But what if you want to put a second revealTrans() on the same page? You can, but you need to do two things.

First, you need to set a new function name in the script. I chose goAway() for my second function name. Then you need to update that name in the Form Button onClick Event Handler.

Then there's the NAME= in the SPAN. Remember how we named the SPAN in the original script Egg1? Well, that NAME connected the SPAN and the JavaScript. This means that if you put another revealTrans() on a page, the first name is dead and cannot be used by anything else. Thus, you have to change the name of the SPAN and each time that name appears in the script.

Here's a hint to do it quickly: Copy the script and previous SPAN on to a separate text editor, like WordPad or SimpleText. Then, choose Replace from the Edit menu. Type in the current name of the SPAN and then what you would like the new name to be and choose to Replace All. Bingo! It's done.

Now you can copy the new script and SPAN and paste it wherever you want it. No sweat! That's what I had to do here. I went with the name Egg2. Clever, huh?

The following code is the second script and SPAN from before. It has a new function name, a new NAME for the SPAN—which has also been changed throughout the script—and is set to go in the opposite direction of the first revealTrans(). The transitions are still set to 12, though. I really do like that number:

<SCRIPT LANGUAGE="javascript">
function goAgain() 
if (Egg2.style.visibility == "hidden") 
Egg2.style.visibility = "visible"; 
else { 
Egg2.style.visibility = "hidden"; 
<INPUT TYPE=button VALUE="Lemme See It" onClick="goAgain();">
<SPAN ID=Egg2 Style="Visibility:hidden;
Filter:revealTrans(duration=2);width:179;height:110"> <IMG SRC="eggs.gif">

No Button

As you can probably tell, using a button to start the effect is not very useful. Just remember that as long as the effect can be surrounded by a SPAN and an Event Handler is used to trigger the function, this can be triggered any number of ways. An onLoad Event Handler can trigger the effect when the page loads. You could also set the effect to trigger using an onMouseOver as illustrated in Figure 3.5.

Figure 3.5Figure 3.5 See the text "Thank You!" coming in?

By the way, I got the effect to occur in less than a second by setting the duration to .25. Faster than that seemed to kill the effect.

  • + Share This
  • 🔖 Save To Your Account