Modifier la couleur de fond d’une page en javascript

Retour

Ci-dessous, des scripts prêts à l’emploi, que j’ai trouvés amusants. (Je ne suis pas l’auteur de ces scripts.)

Modifier la couleur de fond d’une page de manière dynamique

<html> 
  <head> 
    <script language="javascript"> 
function affichefond (i) 
  { 
    r=i; v=i; b=i 
    hexa="0123456789abcdef" 
    fond = hexa.charAt (Math.floor (r/16)) 
    fond = fond + hexa.charAt (r % 16) 
    fond = fond + hexa.charAt (Math.floor (v/16)) 
    fond = fond + hexa.charAt (v % 16) 
    fond = fond + hexa.charAt (Math.floor (b/16)) 
    fond = fond + hexa.charAt (b % 16) 
    document.bgColor = fond 
  }
i=0 
u=1 

function degrade () { 
  if (u==1) 
    { 
      i++ 
      if (i>254) u=0 
    } 

  if (u==0) 
    { 
      i-- 
      if (i<1) u=1 
    }

  affichefond (i) 
  setTimeout("degrade()",30) 
} 
    </script> 
  </head>
  <body onLoad="degrade ();"> 
    Le contenu de ma page Web
  </body>
</html>