hankknight
asked on
Fading table BOTH in and out
Hello.
I use the following script to fade out the contents of a table.
But I also want be able to fade back in. Now it goes from solid to faint, but not back from faint to solid.
Any ideas?
Thanks!
<script>
// Thanks, brunobear
// Thanks, ed987
fade = {
step: 5,
speed : 20,
finalOpacity : 30,
currentOpacity : 100,
elID : null,
init : function(el) {
fade.elID = el;
if(arguments.length>1)
{
fade.currentOpacity=argume nts[1];
fade.finalOpacity=argument s[2];
fade.speed=arguments[3];
if(fade.currentOpacity<fad e.finalOpa city&&fade .step>0)fa de.step*=- 1;
}
if(arguments.length>4)fade .step=argu ments[4];
if (!document.getElementById( el)) return;
fade.setOP(fade.currentOpa city);
fadeInterval = setInterval('fade.doFade() ',fade.spe ed);
},
setOP : function(newOpacity) {
obj = document.getElementById(fa de.elID);
if(newOpacity<10)newOpacit y='0'+newO pacity;
if(newOpacity<100)obj.styl e.opacity = "."+(newOpacity);else obj.style.opacity = 1;
obj.style.filter = "alpha(opacity="+newOpacit y+")";
fade.currentOpacity = newOpacity;
},
doFade : function(obj) {
if (fade.step>0&&(fade.curren tOpacity-f ade.step>f ade.finalO pacity)) {
fade.setOP(fade.currentOpa city - fade.step);
}
else if (fade.step<0&&(fade.curren tOpacity-f ade.step<f ade.finalO pacity)) {
fade.setOP(fade.currentOpa city - fade.step);
}
else {
fade.setOP(fade.finalOpaci ty);
clearInterval(fadeInterval );
}
}
}
</script>
<a href=#" onclick="fade.init('myTabl e','100',' 20','20',' 2');return false">Fade Out</a>
<a href=#" onclick="fade.init('myTabl e','20','1 00','20',' 2');return false">Fade Back In</a>
<table id="myTable" width=550 class="mytableclass" background="http://www.google.com/images/logo.gif"><tr><td height=210>cell 1</td><td>cell 2</td><td>cell 3</td></tr></table>
I use the following script to fade out the contents of a table.
But I also want be able to fade back in. Now it goes from solid to faint, but not back from faint to solid.
Any ideas?
Thanks!
<script>
// Thanks, brunobear
// Thanks, ed987
fade = {
step: 5,
speed : 20,
finalOpacity : 30,
currentOpacity : 100,
elID : null,
init : function(el) {
fade.elID = el;
if(arguments.length>1)
{
fade.currentOpacity=argume
fade.finalOpacity=argument
fade.speed=arguments[3];
if(fade.currentOpacity<fad
}
if(arguments.length>4)fade
if (!document.getElementById(
fade.setOP(fade.currentOpa
fadeInterval = setInterval('fade.doFade()
},
setOP : function(newOpacity) {
obj = document.getElementById(fa
if(newOpacity<10)newOpacit
if(newOpacity<100)obj.styl
obj.style.filter = "alpha(opacity="+newOpacit
fade.currentOpacity = newOpacity;
},
doFade : function(obj) {
if (fade.step>0&&(fade.curren
fade.setOP(fade.currentOpa
}
else if (fade.step<0&&(fade.curren
fade.setOP(fade.currentOpa
}
else {
fade.setOP(fade.finalOpaci
clearInterval(fadeInterval
}
}
}
</script>
<a href=#" onclick="fade.init('myTabl
<a href=#" onclick="fade.init('myTabl
<table id="myTable" width=550 class="mytableclass" background="http://www.google.com/images/logo.gif"><tr><td height=210>cell 1</td><td>cell 2</td><td>cell 3</td></tr></table>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
the 99 should be 100, just tested the value
The explanation is the following:
in the second line you reach thhis part of the code:
if( fade.currentOpacity < fade.finalOpacity && fade.step>0)
fade.step*=-1;
the values are:
if ( 20 <100 && 2>0 )
>>>> set the opacity to -2
but you want it to be +2
to get from 20 to 100.
Nushi.
in the second line you reach thhis part of the code:
if( fade.currentOpacity < fade.finalOpacity && fade.step>0)
fade.step*=-1;
the values are:
if ( 20 <100 && 2>0 )
>>>> set the opacity to -2
but you want it to be +2
to get from 20 to 100.
Nushi.
you need to modify it to the "other way"
if( fade.currentOpacity < fade.finalOpacity && fade.step<0)
fade.step*=-1;
Nushi.
if( fade.currentOpacity < fade.finalOpacity && fade.step<0)
fade.step*=-1;
Nushi.
else {
fade.setOP(fade.finalOpaci
clearInterval(fadeInterval
which sets the opacity the the value u want at the end.
Nushi.