/    Sign up×
Community /Pin to ProfileBookmark

interval not clearing

Not sure what I’m doing wrong here. The interval doesn’t clear though and just continuously runs until the browser locks up.

the first function calls the setInterval and is only called once.

[code]
function fadeIn(id, speed)
{
window[id+’fade’] = setInterval(function() { increaseOpacity(id)}, speed); //i hate internet explorer
}
[/code]

the second function is the function being called

[code]
function increaseOpacity(id)
{
var thelogo = document.getElementById(id);
if(thelogo)
{
thelogo.curOpacity+=.03;
if(thelogo.curOpacity >= 1)
{
window.clearInterval( [id+’fade’] );
}

var mozLevel = thelogo.curOpacity;
var ieLevel = (thelogo.curOpacity)*300; //300 instead of 100 because IE is sloooowwwww

if(ieLevel <= 100) thelogo.style.filter = “alpha(opacity=”+ieLevel+”)”;
thelogo.style.opacity = mozLevel;
} else window.clearInterval( [id+’fade’] );
}
[/code]

Any insight on this would be much appreciated ?

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@toicontienJun 29.2007 — You might need to change all:
window.clearInterval( [id+'fade'] );
To:
window.clearInterval(window[id+'fade']);
Alternately, you could also do:
clearInterval(window[id+'fade']);
Since clearInteral is assumed to be a window object member.
Copy linkTweet thisAlerts:
@dicicco2authorJun 29.2007 — yea, i tryed those before too. i don't understand, in my debugger it is calling the clearIntervals but the interval is never cleared.
Copy linkTweet thisAlerts:
@rootJun 29.2007 — use a normal array to store a reference to the timer you set and then use that array reference to kill that interval timer.
Copy linkTweet thisAlerts:
@Banana_AnandaJun 29.2007 — I'm doubtful that the problem is with the timer referencing. It all looks fine. I rather suspect it is that the condition is never satisfied. Have you tried...?

[code=php]if(thelogo.curOpacity >= 1)
{
alert("hello");
window.clearInterval( [id+'fade'] );
}[/code]


Is the expando property, [FONT="Courier New"]thelogo.[COLOR="Blue"]curOpacity[/COLOR][/FONT], ever initialised ? It could be that the statement: [FONT="Courier New"]thelogo.curOpacity += .03[/FONT] is producing/adding to a string, so the condition ends up being something like:
[code=php]if("undefined03" >= 1)[/code]
which is [FONT="Courier New"][COLOR="Blue"]false[/COLOR][/FONT].
×

Success!

Help @dicicco2 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.8,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...