By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,629 Members | 1,793 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,629 IT Pros & Developers. It's quick & easy.

fade font colour to another

P: n/a
Hi,

I'm trying to build a script which will fade the colour of my text to
another. Now I've got here a litte problem. Whene ever I want to replace
one of the numbers in:
document.getElementById("main_txt").style.color = "rgb(0,0,0)";
by a var, something I can control, like: rgb(red, green, blue) of which
I made shure it were integers by parseInt(); I always get the error in
IE that there is an invalid value for the property. I can not figure out
what is wrong about the value. Can anyone give my somebody help me out
on this

Thanks in advance, Maarten

ps.

function change_colour(red, green, blue)
{

dest_red = 202;
dest_green = 207;
dest_blue = 222;

steps_red = (dest_red - red)/100;
steps_green = (dest_green - green)/100;
steps_blue = (dest_green - green)/100;
for(step = 1 ; step <= 100 ; step++)
{

red = parseInt(red);
grr = parseInt(5);
document.getElementById("main_txt").style.color = "rgb(grr,0,0)";

}
}
Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Muffinman wrote:
Hi,

I'm trying to build a script which will fade the colour of my text to another. Now I've got here a litte problem. Whene ever I want to replace one of the numbers in:
document.getElementById("main_txt").style.color = "rgb(0,0,0)";
by a var, something I can control, like: rgb(red, green, blue) of which I made shure it were integers by parseInt(); I always get the error in IE that there is an invalid value for the property. I can not figure out what is wrong about the value. Can anyone give my somebody help me out on this

Thanks in advance, Maarten

ps.

function change_colour(red, green, blue)
{

dest_red = 202;
dest_green = 207;
dest_blue = 222;

steps_red = (dest_red - red)/100;
steps_green = (dest_green - green)/100;
steps_blue = (dest_green - green)/100;
for(step = 1 ; step <= 100 ; step++)
{

red = parseInt(red);
grr = parseInt(5);
document.getElementById("main_txt").style.color = "rgb(grr,0,0)";
}
}


This:

document.getElementById("main_*txt").style.color = "rgb(grr,0,0)";

....will set the CSS color attribute of that element to - literally -
"rgb(grr,0,0)". To get the variable 'grr' (maybe 'grn' would be better)
to interpolate properly, you'll need to discontinue the quotes to force
it to be evaluated ('looked up') as a variable:

document.getElementById("main_*txt").style.color = "rgb(" + grr +
",0,0)";

Jul 23 '05 #2

P: n/a
Muffinman wrote:
Hi,
I'm trying to build a script which will fade the colour of my text to
another. Now I've got here a litte problem. Whene ever I want to replace
one of the numbers in:
document.getElementById("main_txt").style.color = "rgb(0,0,0)";
by a var, something I can control, like: rgb(red, green, blue) of which
I made shure it were integers by parseInt(); I always get the error in
IE that there is an invalid value for the property. I can not figure out
what is wrong about the value. Can anyone give my somebody help me out
on this
Thanks in advance, Maarten


I found this a few days ago. Click Preview and watch the text at the top
of the page.

http://www.bosiljak.hr/fadermaker/

Mike
Jul 23 '05 #3

P: n/a
Muffinman wrote:
Hi,

I'm trying to build a script which will fade the colour of my text to
another. Now I've got here a litte problem. Whene ever I want to replace
one of the numbers in:
document.getElementById("main_txt").style.color = "rgb(0,0,0)";
by a var, something I can control, like: rgb(red, green, blue) of which
I made shure it were integers by parseInt();
Your use of 'make sure' infers that you are using parseInt() :

1. to validate that the variable is an integer

2. to convert a string to an integer

Both uses are not appropriate. If you are using it as validation,
better methods are suggested here:

<URL:http://www.merlyn.demon.co.uk/js-valid.htm#VNP>

If you are using it to convert a string to a number, see below.
I always get the error in
IE that there is an invalid value for the property. I can not figure out
what is wrong about the value. Can anyone give my somebody help me out
on this

Thanks in advance, Maarten

ps.

function change_colour(red, green, blue)
{

dest_red = 202;
dest_green = 207;
dest_blue = 222;

steps_red = (dest_red - red)/100;
steps_green = (dest_green - green)/100;
steps_blue = (dest_green - green)/100;
for(step = 1 ; step <= 100 ; step++)
{

red = parseInt(red);
You do not provide any code where you actually use 'red', so I'll use
an example from a subsequent line. Remove the parseInt() line above
and do:

...("main_txt").style.color = "rgb(" + +red + ",0,0)";

the '+' character converts 'red' to a number - presuming that you
have already validated that 'red' contains a suitable value (0-255).

In any case, I think it's perfectly OK for 'red' to be a string in
this instance.
grr = parseInt(5);


for grr to be a number:

grr = 5;

does the job as per your earlier use.

Do a search on why parseInt() should always be used with a radix
parameter to discover why its use is discouraged, particularly where
more concise alternatives exist.

--
Fred
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.