M
manu3d
Hi everybody!
I'm trying to put the icing on a cake
but I'm having one final problem.
The cake is actually a fadeIn function
that takes in input an element id(in my
case a <DIV> block) and a maximum opacity
parameter.
The element fades in correctly and reaches
the desired opacity. So we could say that
the function is doing the right thing.
Unfortunately, from a purely visual point
of view, -IF- the maximum opacity is set
to 1.0, there seem to be a brief "double flash"
just before the full opacity is reached.
That is: if I print out the values of the
opacity for each iteration of the function
I get what I would expect:
0.5, 0.6, 0.7, 0.8, 0.9, 1.0
but the following sequence of values
better describes -what I see-:
0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 0.0, 1.0
Notice that the length of the "0.0" flash
remains the same even if I increase the
milliseconds in the setTimeout() call.
It almost looks like some kind of browser
rendering problem rather than a scripting
issue.
Can anybody confirm my hypothesis?
Thanks in advance for your help!
Sincerely,
Manu
P.S. This is the code of the fade-in function I wrote,
together with its sibling fade-out, for completeness
and for anybody to use (although it's only Mozilla
compatible at this point...)
----
var fadeInTO, fadeOutTO;
function layer_fadeIn(layerName, maxOpacity)
{
clearTimeout(fadeOutTO);
myOpacity = document.getElementById(layerName).style.opacity;
if(myOpacity < maxOpacity)
{
myOpacity -= -0.10;
document.getElementById(layerName).style.opacity=myOpacity;
var cmd2run="layer_fadeIn('"+layerName+"',"+maxOpacity+")";
var fadeSpeed=500;
fadeInTO=setTimeout(cmd2run,fadeSpeed);
}
}
function layer_fadeOut(layerName, maxTransparency)
{
clearTimeout(fadeInTO);
myOpacity = document.getElementById(layerName).style.opacity;
if(myOpacity > maxTransparency)
{
myOpacity -= 0.10;
document.getElementById(layerName).style.opacity=myOpacity;
var
cmd2run="layer_fadeOut('"+layerName+"',"+maxTransparency+")";
var fadeSpeed=10;
fadeOutTO=setTimeout(cmd2run,fadeSpeed);
}
}
I'm trying to put the icing on a cake
but I'm having one final problem.
The cake is actually a fadeIn function
that takes in input an element id(in my
case a <DIV> block) and a maximum opacity
parameter.
The element fades in correctly and reaches
the desired opacity. So we could say that
the function is doing the right thing.
Unfortunately, from a purely visual point
of view, -IF- the maximum opacity is set
to 1.0, there seem to be a brief "double flash"
just before the full opacity is reached.
That is: if I print out the values of the
opacity for each iteration of the function
I get what I would expect:
0.5, 0.6, 0.7, 0.8, 0.9, 1.0
but the following sequence of values
better describes -what I see-:
0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 0.0, 1.0
Notice that the length of the "0.0" flash
remains the same even if I increase the
milliseconds in the setTimeout() call.
It almost looks like some kind of browser
rendering problem rather than a scripting
issue.
Can anybody confirm my hypothesis?
Thanks in advance for your help!
Sincerely,
Manu
P.S. This is the code of the fade-in function I wrote,
together with its sibling fade-out, for completeness
and for anybody to use (although it's only Mozilla
compatible at this point...)
----
var fadeInTO, fadeOutTO;
function layer_fadeIn(layerName, maxOpacity)
{
clearTimeout(fadeOutTO);
myOpacity = document.getElementById(layerName).style.opacity;
if(myOpacity < maxOpacity)
{
myOpacity -= -0.10;
document.getElementById(layerName).style.opacity=myOpacity;
var cmd2run="layer_fadeIn('"+layerName+"',"+maxOpacity+")";
var fadeSpeed=500;
fadeInTO=setTimeout(cmd2run,fadeSpeed);
}
}
function layer_fadeOut(layerName, maxTransparency)
{
clearTimeout(fadeInTO);
myOpacity = document.getElementById(layerName).style.opacity;
if(myOpacity > maxTransparency)
{
myOpacity -= 0.10;
document.getElementById(layerName).style.opacity=myOpacity;
var
cmd2run="layer_fadeOut('"+layerName+"',"+maxTransparency+")";
var fadeSpeed=10;
fadeOutTO=setTimeout(cmd2run,fadeSpeed);
}
}