/    Sign up×
Community /Pin to ProfileBookmark

window.setTimeout using a for-loop with problems

Hello, I’m trying to make some text get lighter in only 300ms. I have succeded doing 10 lines of window.setTimeout(document.getElementById(‘text’).style.MozOpacity=0.9,20), window.setTimeout(document.getElementById(‘text’).style.MozOpacity=0.8,40) and so on..

However I can’t make this work using a for-loop. Here’s my code:

[code=html]function go() {
var div=document.getElementById(‘text’);
var no=1.0;
var time=20;
for(var i=10;i>10;i–) {
window.setTimeout(‘div.style.MozOpacity=no’,time);
no=no-0.1;
time=time+20; } }[/code]

The only thing I get is always the same black text. If anyone can suggest me a better form of doing this, I’ll be very grateful.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@hyperliskNov 22.2006 — <i>
</i>opacity = 1;
wait = 30;
function fade(id){
var what = document.getElementById(id);
what.style.MozOpacity = opacity;
opacity -= 0.1;
if(opacity &gt;= 0){
setTimeout('fade("'+id+'")',wait);
} else {
opacity = 1;
}
}

function go(){
fade('text');
}
Copy linkTweet thisAlerts:
@turbocuecaauthorNov 25.2006 — Works alright, thanks for the help.
×

Success!

Help @turbocueca 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...