Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / JavaScript / March 2005



Tip: Looking for answers? Try searching our database.

fade font colour to another

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Muffinman - 31 Mar 2005 03:53 GMT
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)";

      }
      }
RobB - 31 Mar 2005 04:05 GMT
> 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:
[quoted text clipped - 29 lines]
>        }
>        }

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)";
mscir - 31 Mar 2005 05:57 GMT
> Hi,
> I'm trying to build a script which will fade the colour of my text to
[quoted text clipped - 7 lines]
> 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
Fred Oz - 31 Mar 2005 06:07 GMT
> Hi,
>
[quoted text clipped - 4 lines]
> 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
[quoted text clipped - 20 lines]
>
>       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.

Signature

Fred

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.