Click to See Complete Forum and Search --> : What's wrong w/ this code?
krautinator
10-21-2003, 09:56 AM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled</title>
<script>
function FadeIn(newopacity){
if(document.all && newopacity < 100){
newopacity += 10
document.all.faded.style.filter="alpha(opacity=" +newopacity+ ")"
setTimeout ("fadeIn(" +newopacity+ ")", 10)
}
}
function FadeOut(newopacity){
if(document.all && newopacity >30){
newopacity -= 10
document.all.faded.style.filter="alpha(opacity=" +newopacity+ ")"
setTimeout ("fadeIn(" +newopacity+ ")", 10)
}
}
</script>
<style type="text/css">
#faded {filter:alpha(opacity=30)}
</style>
</head>
<body>
<img id="faded" onmouseover="fadeIn(30)" onmouseout="fadeOut(30)" src="metal.gif"></body>
</html>
Does anybody have any idea why this code isn't working?
clairec666
10-21-2003, 10:09 AM
Ah, I can see the problem (after much puzzling)
In the script block, you have named the functions FadeIn() and FadeOut() (capital F) but without the capital f when you call the functions with the onmouseover/onmouseout.
To avoid this again, copy and past the name of the function when assigning it to the event handler instead of copying and allowing for mistakes
krautinator
10-21-2003, 10:23 AM
if you could for just a moment:
visualize me sighing breifly, then banging my head repeatedly on the keyboard...
I knew it was gonna somethin' stupid and simple like that
Knew it, Knew it,Knew it
It always is when it gets down to the wire...
thnx alot
krautinator
10-21-2003, 10:42 AM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled</title>
<script>
function fadeIn(newopacity){
if(document.all && newopacity < 100){
newopacity += 10
document.all.faded.style.filter="alpha(opacity=" +newopacity+ ")"
setTimeout ("fadeIn(" +newopacity+ ")", 10)
}
}
function fadeOut(newopacity){
if(document.all && newopacity > 30){
newopacity -= 10
document.all.faded.style.filter="alpha(opacity=" +newopacity+ ")"
setTimeout ("fadeOut(" +newopacity+ ")", 10)
}
}
</script>
<style type="text/css">
#faded {filter:alpha(opacity=30)}
</style>
</head>
<body>
<img id="faded" src="metal.gif" onmouseover="fadeIn(30)" onmouseout="fadeOut(100)" >
</body>
</html>
I also noticed one small other error and corrected it (if anyone cares) in the fadeOut function, newopacity has start out at 100 in order to work correctly
Webskater
10-21-2003, 11:07 AM
You should not be so hard on yourself - you should find the idiot who decided Javascript would be case sensitive and then, not so gently, bang their head against a wall until they understand you do not need case sensitivity in a programming language. How many times a day do I think "did I name that function 'showthis' or 'ShowThis' or 'showThis' or 'Showthis' and have to scroll up to check. Why am I so inconsistent? Because the rest of my pages in ASP and SQL demand names like ShowThis for readibility but javascript, incredibly irritating javaScript, falls over if you make one simple, tiny case mistake.
Sorry, I feel a bit better now.
krautinator
10-21-2003, 11:15 AM
yeah
hahahahaaaahah LOL
and don't even get me started on that cross - browser coding
crap!
Federal Government should start sending people to prison over that.
here's an idea:
give the W3C an Army to enforce their standards!
Maybe then Billy Gates 'll get off his Evil Empire high horse.
scurvyrickets
10-22-2003, 06:07 PM
Cool effect.
And I have to second, or third, or millionth, your sentiment about cross-browser compatibility. What a freakin' nightmare.