Fade-In Text / Images Question

So, I don’t really know much about Javascript. I want text and images on a page to fade in when the page is loaded. The elements would start at an opacity of zero and go up to 100%.

I found some random code on various sites and pasted it together and kind of got something working, but it isn’t really what I want. It makes the text start at white and fade up to black, so I wouldn’t be able to use this on any other background besides white.

And this code is using RGB numbers and I couldn’t figure out how to just use standard web hexcodes like #FFFFFF.


<script language="JavaScript1.2">
hex=255 // Initial color value.

function fadetext(){ 
if(hex>0) { //If color is not black yet
hex-=11; // increase color darkness
hex=255 //reset hex value

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {

addLoadEvent(function() {
  /* more code to run on page load */ 



<div id="sample" style="width:100%"><h3>John slowly faded into view</h3></div>