Firefox & getElementById('main_txt') doesn't work

M

Muffinman

Howdy,

I've got here a sample of my function which is supposed to fade a
certain piece of text to another colour. This line is then located in a
for loop and it works pretty well in IE 6. However, in Firefox, and thus
I assume it will be the same in Netscape and Mozilla, it gives a problem
with the: getElementById('main_txt'). Due to that in setTimeout("",) it
requires the "" signes and thus I can not use the same ones in the
getElement part. IE has no problem with using '' in there, Firefox,
however, does. Can anyone think of how to get around this and make
firefox do this?

window.setTimeout("document.getElementById('main_txt').style.color =
'rgb("+red+","+green+","+blue+")'",delay*step);

Thanks in advance, Maarten
 
Z

Zifud

Muffinman said:
Howdy,

I've got here a sample of my function which is supposed to fade a
certain piece of text to another colour. This line is then located in a
for loop and it works pretty well in IE 6. However, in Firefox, and thus
I assume it will be the same in Netscape and Mozilla, it gives a problem
with the: getElementById('main_txt'). Due to that in setTimeout("",) it
requires the "" signes and thus I can not use the same ones in the
getElement part. IE has no problem with using '' in there, Firefox,
however, does. Can anyone think of how to get around this and make
firefox do this?

window.setTimeout("document.getElementById('main_txt').style.color =
'rgb("+red+","+green+","+blue+")'",delay*step);

Let's end this misery:

<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01//EN'
'http://www.w3.org/TR/html4/strict.dtd'>
<html><head>
<title>f-f-f-fader</title>
<meta http-equiv='Content-Type'
content='text/html; charset=ISO-8859-1'>
</head>

<body onload="change_colour('xx','0','0','0');">

<script type="text/javascript">

function change_colour(ele,r,g,b){
var s = document.getElementById(ele);
var dest_red = 202;
var dest_green = 207;
var dest_blue = 222;
var lag = 500;
var steps = 10;

// Ensure values are numbers so can add to them
r = +r; g = +g; b = +b;

var steps_red = (dest_red - r)/steps;
var steps_green = (dest_green - g)/steps;
var steps_blue = (dest_blue - b)/steps;

// Start the timer
s.timer = window.setInterval(function() {
r += steps_red;
g += steps_green;
b += steps_blue;

// If we're at the end (or really close), finish it
if ( r > dest_red || g > dest_green || b > dest_blue) {
s.style.color = 'rgb('
+ dest_red + ','
+ dest_green + ','
+ dest_blue + ')';
s.innerHTML = '<b>I\'m done...</b>';

// Stop the timer
window.clearTimeout(s.timer);
s.timer = null;

} else {

// ensure values are integers
s.style.color = 'rgb('
+ Math.floor(r) + ','
+ Math.floor(g) + ','
+ Math.floor(b) + ')';

// Just to show the values as we go...
s.innerHTML += '<br>' + r + ', ' + g + ', ' + b;
}
}, lag);
}

</script>

<span id="xx" style="color: blue;"><b>HI TO EVERYONE</b></span>

</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top