How exactly does a background fader script work???

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nick

    How exactly does a background fader script work???

    Does a background fader work by...


    A) Changing the color after a long 'loop' statement???

    B) Changing the color, then waiting a bit, then changing the color
    again???


    To me it seems B would be less cpu/browser intensive. Does anyone know
    how exactly this works and an example script? Thanks! -Nick
  • Evertjan.

    #2
    Re: How exactly does a background fader script work???

    Nick wrote on 18 jul 2003 in comp.lang.javas cript:
    [color=blue]
    > Does a background fader work by...
    >
    >
    > A) Changing the color after a long 'loop' statement???
    >
    > B) Changing the color, then waiting a bit, then changing the color
    > again???
    >
    >
    > To me it seems B would be less cpu/browser intensive. Does anyone know
    > how exactly this works and an example script? Thanks! -Nick
    >[/color]

    <http://www.google.com/search?q=%22bac kground%20fader %22%22javascrip t%22>

    249 hits

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)

    Comment

    • Nick

      #3
      Re: How exactly does a background fader script work???

      Well I found a good simple example script.

      The setTimeout() function was the snip I guess I was looking for. Ive
      seen many other scripts that just rely on a loop to change the colors
      - the problem though - faster cpu, the faster colors change; not very
      uniform. The setTimeout() fixes that. Here it is!!!



      <script language="Javas cript">
      // 'i' increments the RGB values
      // 't' changes the frequency of time
      var t = "10";
      function fader(i) {
      var RGBstring = "rgb("+i+","+i+ ","+i+")";
      document.bgColo r = RGBstring;
      setTimeout("fad er("+(i-1)+")",t);
      }
      </script>

      <FORM NAME="backgroun d">
      <INPUT TYPE="button" VALUE="Start" onClick="fader( 255)">
      </FORM>

      Comment

      Working...