...

View Full Version : Loop not stopping :O :(



martynball
07-22-2010, 03:00 AM
// Values for fading
var fadeBy = 10; //Amount to fade by
var fadeTime = 120; //Time in milliseconds to fade.
var ie_counter = 0; //Counter for crappy IE.
var fade_to = 70;
function fader(obj) {
var div = document.getElementById(obj);

//Object details
var opacity = div.style.opacity * 100 + fadeBy; //Fade (FF)
ie_counter = ie_counter + fadeBy;
var opacity_ie = div.style.filter = "alpha(opacity=" + ie_counter + ")"; //Fade (IE)
div.style.opacity = opacity / 100;
if ( ie_counter != fade_to || opacity != fade_to ) {
setTimeout( "fader('" + obj + "')", fadeTime );
}
}


The loop stops for firefox (good browser), but not for internet explorer for some reason :/

Apart for the fact that IE is crap why is this?

RandomUser531
07-22-2010, 03:47 AM
if ( ie_counter != fade_to || opacity != fade_to )To stop, both those conditions have to evaluate false. All you have to do is determine which one doesn't.

Old Pedant
07-22-2010, 03:59 AM
Because opacity != fade_to will *ALWAYS* be TRUE when using IE!!!! opacity will be undefined!

So how CAN it stop???

You are working too hard. Keep it simple:


var fadeBy = 10; //Amount to fade by
var fadeTime = 120; //Time in milliseconds to fade.
var fade_counter = 0; var fade_to = 70;
function fader(obj) {
var div = document.getElementById(obj);

fade_counter += fadeBy;
div.style.filter = "alpha(opacity=" + fade_counter + ")"; //Fade (IE)
div.style.opacity = opacity / 100;
if ( fade_counter < fade_to ) {
setTimeout( "fader('" + obj + "')", fadeTime );
}
}

You should use fade_counter < fade_to as the test, in case you have values such as fadeBy = 7 and fade_to = 80!!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum