hankknight
asked on
Dynamically fading table
Hello, I use the following to fade the content of a table:
https://www.experts-exchange.com/questions/21909311/Apply-CSS-with-JS-function.html
It works well, but it is jumpy. I want it to be a smooth transition, so that in 1 second, it fades from 100% opacity to 50% opacity. This needs to be cross browser.
Any ideas?
Thanks!
<style>
.yourClass {
filter:alpha(opacity=50);
opacity: 0.50;
-moz-opacity:0.50;
}
</style>
<script>
///// thanks pravinasar and 0h4crying0utloud
function fadeTable(tname) {
document.getElementById(tn ame).class Name = "yourClass";
}
</script>
<a href=#" onclick="return fadeTable('myTable');retur n false">fade table</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>
https://www.experts-exchange.com/questions/21909311/Apply-CSS-with-JS-function.html
It works well, but it is jumpy. I want it to be a smooth transition, so that in 1 second, it fades from 100% opacity to 50% opacity. This needs to be cross browser.
Any ideas?
Thanks!
<style>
.yourClass {
filter:alpha(opacity=50);
opacity: 0.50;
-moz-opacity:0.50;
}
</style>
<script>
///// thanks pravinasar and 0h4crying0utloud
function fadeTable(tname) {
document.getElementById(tn
}
</script>
<a href=#" onclick="return fadeTable('myTable');retur
<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
Thanks. That is very interesting, but a bit heavier than I would like. I would like to see this accomplished with a fraction the amount of code that Yahoo's animation uses.
ok - but i assume that's more the effect you want? let me work up some code for you
ASKER
Thanks, yes, that is what I am looking for, but I want it as lightweight as possible.
here's what i have currently, for firefox only - i need to find the js to change the filter value for IE, but this should get you started:
<script>
fade = {
speed : 5,
finalOpacity : 30,
currentOpacity : 100,
elID : null,
init : function(el) {
fade.elID = el;
if (!document.getElementById( el)) return;
fadeInterval = setInterval('fade.doFade() ',fade.spe ed);
},
doFade : function(obj) {
obj = document.getElementById(fa de.elID);
if (fade.currentOpacity>fade. finalOpaci ty) {
var newOpacity = fade.currentOpacity - 1;
obj.style.opacity = "."+(newOpacity);
fade.currentOpacity = newOpacity;
} else {
clearInterval(fadeInterval );
}
}
}
</script>
<a href=#" onclick="fade.init('myTabl e');return false">fade table</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>
<script>
fade = {
speed : 5,
finalOpacity : 30,
currentOpacity : 100,
elID : null,
init : function(el) {
fade.elID = el;
if (!document.getElementById(
fadeInterval = setInterval('fade.doFade()
},
doFade : function(obj) {
obj = document.getElementById(fa
if (fade.currentOpacity>fade.
var newOpacity = fade.currentOpacity - 1;
obj.style.opacity = "."+(newOpacity);
fade.currentOpacity = newOpacity;
} else {
clearInterval(fadeInterval
}
}
}
</script>
<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.
btw - i normally like to keep styles seperate from the JS, as was in your original script. i'd rather change the class name than update the styles dynamically. but in this situation that doesn't work as you'd need at least 50 different classes, one for each opacity level, and that simply isn't worth it.
so, we've set all your variables at the top of the script so they are easy to locate and change, and none of the actual values are buried anywhere within the script.
so, we've set all your variables at the top of the script so they are easy to locate and change, and none of the actual values are buried anywhere within the script.
ASKER
Thanks! It is perfect.
ASKER
I have posted a related question here:
https://www.experts-exchange.com/questions/21909621/Fading-IN-and-OUT-from-JS-function.html
https://www.experts-exchange.com/questions/21909621/Fading-IN-and-OUT-from-JS-function.html
http://developer.yahoo.com/yui/examples/animation/fade.html
Get more info about the animation utility here:
http://developer.yahoo.com/yui/animation/
bruno