You should look into jQuery. He will do all this for you using the effects functions or plugins.
However, in response to a question:
Typically, web browsers use only one stream of updates for the user interface, which is also used to execute Javascript code. Therefore, the browser will fully execute your cycle and only then refresh the page after its completion (i.e. all RGG = 255,255,255).
Try using window.setTimeout or window.setInterval to call a function that increments RGB values. This allows you to update the browser browser stream to update the display after each call (between interval or timeout).
(I believe all major browsers work this way, including Firefox).
Note: setInterval and setTimeout execute code on the same user interface thread. They simply add a timer callback to the window message loop, and it calls and executes at the right time.
Therefore, if other Javascript code or user interface updates were being executed at that time, the timer function should wait. Therefore, the function is not guaranteed at the exact time indicated. Also (on Windows) the maximum resolution is much less than 1 millisecond, often about 1/20 second or about 50 milliseconds.
source share