473,396 Members | 1,914 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

fade font colour to another

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
3 2411
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Louise | last post by:
Hi I have written an HTML pages which does not have any colour specifying tags as far I know. When I view this in an Microsoft internet explorer browser it appears with a white background and...
1
by: Robert Skidmore | last post by:
I am building an application that will fade one panel to another panel. Both panels will have picture boxes in them (thumbnails). This is what I have tried: private void...
1
by: BillZondlo | last post by:
Can someone look at this and tell me why, when I call this from my main app, it displays fine (fades form in and out) but then before my main app displays, I see other dialog boxes flash...
0
by: aziz001 | last post by:
My forms have the standard 'Control' BackColor. When I use the normal fade in algorithm the fade in colour is black and then the form suddenly pops up. How do I fade in using the Control color (or...
1
by: spgedwards | last post by:
I am trying to run a basic script that displays an existing jpeg image and writes some text over it. Sounds simple, but I cannot seem to be able to colour the font correctly. In the example below...
4
by: H-S | last post by:
Please help. This is a real puzzler! Originally posted on microsoft.public.dotnet.framework.windowsforms but no answer found! I have a read-only textBox which shows the results of a selection...
3
by: Johny | last post by:
I use PIL to write some text to a picture.The text must be seen wery clearly. I write the text to different pictures but to the same position. As pictures maybe different, colour, in the...
4
by: pt36 | last post by:
Hi I have a small script function photo(a){ var photo = a ; document.getElementById(photoID).innerHTML = photo; } and on the body
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.