I couldn't find how to do this anywhere. Basically I want to toggle an elements opacity off and on through a link. The code I have is below but it doesn't read the value of the opacity to see if the div is currently 'on' or 'off'.
I haven't found anywhere how to easily read the value of the opacity. Right now I am working in Firefox, but will want to make it IE friendly also.
function show_hide(obj){
var state = document.getElementById(obj).style.opacity;
if (state == '90')
opacity(obj, 0, 90, 500);
else
opacity(obj, 90, 0, 500);
}
function opacity(id, opacStart, opacEnd, millisec) {
var speed = Math.round(millisec / 100);
var timer = 0;
if(opacStart > opacEnd) {
for(i = opacStart; i >= opacEnd; i--) {
setTimeout("changeOpac(" + i + ",'" + id + "')",(timer speed));
timer++;
}
} else if(opacStart < opacEnd) {
for(i = opacStart; i <= opacEnd; i++)
{
setTimeout("changeOpac(" + i + ",'" + id + "')",(timer speed));
timer++;
}
}
}
function changeOpac(opacity, id) {
var object = document.getElementById(id).style;
object.display = 'block';
object.opacity = (opacity / 100);
object.MozOpacity = (opacity / 100);
object.KhtmlOpacity = (opacity / 100);
object.filter = "alpha(opacity=" + opacity + ")";
}