Help Modifying Fade Script

I have a fade out script that I like a lot, but I wanted to change one thing.

When I click an action, I want the script to run on the div (which I’m currently doing), but when a hidden frame page finishes loading, I want it to reverse the fade and fade back in. So, either stop the fade out in progress and then fade back in from that point or, if the fade has completed to zero, fade in the div layer all the way again.

Here is the script:

// @name      Slowly Fade
// @version   0.88
// @author    Richard D. LeCour
// @namespace

var opacity = 96; // Avoid starting at 100% due to Mozilla bug
var slowly = {
	fade : function (id) {
		this.fadeLoop(id, opacity);
	fadeLoop : function (id, opacity) {
		var o = document.getElementById(id);
		if (opacity >= 5) {
			slowly.setOpacity(o, opacity);
			opacity -= 4;
			window.setTimeout("slowly.fadeLoop('" + id + "', " + opacity + ")", 50);
		} else { = "none";
	setOpacity : function (o, opacity) { = "alpha(style=0,opacity:" + opacity + ")";	// IE = opacity / 100;				// Konqueror = opacity / 100;					// Mozilla (old) = opacity / 100;					// Mozilla (new)

I call the script as I send a GET request to a hidden frame on page (which swaps out a div on the page with innerHTML. The div fades out beautifully and I edited the script to fade it back in automatically once it gets to opacity of 4. But, I’d rather have the script fade back in once a call has been made to javascript to reverse the fade. Right now I am just guessing when the page might be finished loading, but would like to be more exact on the switch of fade. So the iframe loads and does:


I have everything set to go but the script (and call) to do the reverse.

All help appreciated.


Maybe I can make this question a bit easier. I just want to have a secondary function for fading back in.

So, to fade out I’ve been doing


How can I add to this code so if I did:


The div layer will then return.



I tried adding that to the onclick but got:

Error: missing : in conditional expression
Line: 1, Column: 37
Source Code:


Do I need to edit the primary function too?


Nevermind. I rewrote it and got it to work.