/    Sign up×
Community /Pin to ProfileBookmark

help with fadding div..

I am attempting fade a div in or out depending on the current opacity.

Here is what I have so far.

[code]
function fade(id) {
var div = document.getElementById(id).style;
var start = (div.opacity * 100);
var end = 100;
var timer = 0;
var speed = 500;
if (start >= end) {
for (var i = start; i < end; i–) {
setTimeout(“startFade(” + i + “, ‘” + id + “‘);”, (timer * speed));
timer++;
}
} else if (start < end) {
for (i = start; i >= end; i++) {
setTimeout(“startFade(” + i + “, ‘” + id + “‘);”, (timer * speed));
timer++;
}
}
}

function startFade(opac, id) {
var div = document.getElementById(id).style;
div.opacity = (opac / 100);
div.filter = ‘alpha(opacity=’ + opac + ‘)’;
}[/code]

I have narrowed it down to the for loop. I did this by placeing alerts through out the code. Any suggestions as to why the for loop is not being called?

Thanks,
Tom

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@Arty_EffemOct 22.2006 — I am attempting fade a div in or out depending on the current opacity.

Here is what I have so far.

<i>
</i>function fade(id) {
var div = document.getElementById(id).style;
var start = (div.opacity * 100);
var end = 100;
var timer = 0;
var speed = 500;
if (start &gt;= end) {
for (var i = start; i &lt; end; i--) {
setTimeout("startFade(" + i + ", '" + id + "');", (timer * speed));
timer++;
}
} else if (start &lt; end) {
for (i = start; i &gt;= end; i++) { <br/>
setTimeout("startFade(" + i + ", '" + id + "');", (timer * speed));
timer++;
}
}
}

function startFade(opac, id) {
var div = document.getElementById(id).style;
div.opacity = (opac / 100);
div.filter = 'alpha(opacity=' + opac + ')';
}



I have narrowed it down to the for loop. I did this by placeing alerts through out the code. Any suggestions as to why the for loop is not being called?

Thanks,

Tom[/QUOTE]

I suspect that it is being entered, but for both loops the test condition clearly fails from the start.
Copy linkTweet thisAlerts:
@hsdhmanOct 22.2006 — tomfmason,

For the for loop to execute, the condition in the middle term must work out to be true. You seem to have it backwards here, so just switch the directions of the < and > signs in your if statements and it might work!
Copy linkTweet thisAlerts:
@EfferentOct 23.2006 — When you want ot change an element's opacity value use these statements

ImageObj.style.filters.alpha.opacity=90 in IE

ImageObj.style.MozOpacity=0.9 in Mozilla browser
×

Success!

Help @tomfmason 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.18,
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,
)...