Use these to jump around or read it all…
[Make It Disappear]
[Transition Numbers]
[Make It Go Away]
[No Button]
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.
Do you want a cool effect? Dig this. Click the gray buttons below.
What you’re seeing there is the revealTrans() filter at work. Two separate JavaScripts are using the filter to make a SPAN disappear then reappear. I’ll show you the first one first, then explain the second one quickly. (It’s just like the first one only backward — there’s good writing, huh?)
Make It Disappear
As I said above, the image, “egg.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;
Filter:revealTrans(duration=2);width:179;height:110″>
<IMG SRC=”eggs.gif”>
</SPAN>
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 tag displaying the egg.gif. There is a NAME given to the span, Egg1. That will link it to the JavaScript we’ll hit in a moment. Also, inside the SPAN are some Style Sheet commands and the filter. Note that the visibility of the SPAN is set to “visible.” That will change in the next one. Then comes the Filter:revealTrans(duration=2). You can probably guess the “2” means two seconds for the effect. Then the height and width of the image so the span fits it perfectly.
Okay. Got the SPAN? Good. Now the Script that does the dirty work:
<SCRIPT LANGUAGE=”javascript”>
function go() {
Egg1.filters[0].Apply();
if (Egg1.style.visibility == “visible”)
{
Egg1.style.visibility = “hidden”;
Egg1.filters.revealTrans.transition=12;
}
else
{
Egg1.style.visibility = “visible”;
Egg1.filters[0].transition=12;
}
Egg1.filters[0].Play();
}
</SCRIPT>
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.
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! (If you didn’t catch it: if you click the button after the SPAN disappears, it’s come back.) Nothing to it!
Transition Numbers
If you’ve read over my Transition DHTML tutorial then you’ve seen these before. There are 22 different transitions to choose from. There is also transition 23 which chooses a number at random. I happen to like 12.
And no, you do not have to have both transitions set to 12. It can be two different numbers. Here are the magic 23:
Transition # | What Happens |
1 | Reveal from inside out |
2 | Scroll in from outer parts |
3 | Scroll out from center |
4 | Scroll up from button |
5 | Scroll down from top |
6 | Scroll left to right |
7 | Scroll right to left |
8 | Vertical Blinds left to right |
9 | Horizontal Blinds top to bottom |
10 | Combination of 8 and 9 |
11 | Looks a lot like 8 |
12 | Comes in in pixels |
13 | Scroll in from outer parts |
14 | Scroll out from center |
15 | Close from both top and bottom |
16 | Open from center to top and bottom |
17 | Diagonal roll from right to left |
18 | Different angle diagonal roll right to left |
19 | Number 17: the other way |
20 | Number 18: the other way |
21 | Random horizontal lines |
22 | Random vertical lines |
23 | Completely Random |
Cycle appears to start again after this… |
Any one will work just fine. Some are more interesting than others.
Make It Go Away
There are really two things to discuss here: 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 above go from invisible to visible, then 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.” Remember… they’re one in the SPAN.
But what if you want to put a second revealTrans() on the same page? You can. I have two on this page. You need to do two things.
1.
First off, 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.
2.
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. That 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 SPAN above onto a separate text editor, like WordPad or SimpleText. Then, choose “Replace” from the EDIT menu. Put in the current name of the SPAN and then what you would like the new name to be and choose to Replace All. Bingo. 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 above. 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()
{
Egg2.filters[0].Apply();
if (Egg2.style.visibility == “hidden”)
{
Egg2.style.visibility = “visible”;
Egg2.filters.revealTrans.transition=12;
}
else
{
Egg2.style.visibility = “hidden”;
Egg2.filters[0].transition=12;
}
Egg2.filters[0].Play();
}
</SCRIPT>
<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”>
</SPAN>
No Button
As you can probably tell, using a button to fire this transition is not very useful. Just remember that as long as the thing can be surrounded by a SPAN, and an Event Handler is used to trigger the function, this can be fired 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. Like so:
Thank you!
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.
Enjoy!
[Make It Disappear]
[Transition Numbers]
[Make It Go Away]
[No Button]