背景色を変化させる MENU
2026/02/16日に変更
「document.bgColor」が非推奨となったので、
「document.body.style.backgroundColor」に変更した。


Source
    <html lang="ja"> <head> <title>javascript</title> <script> var sw = new Array(1,5,10); var rgb = new Array(0,0,0); var timer_is_set=false; function Mode16(n){ crgb=((n>255)? 255:((n<0)? 0:n)).toString(16); if(n<16)crgb="0"+crgb; return crgb; } function chg_bg_color(){ for(var i=0;i<3;i++) { sw[i] = (rgb[i]<=0)? sw[i]:((rgb[i]>=255)? 0-sw[i]:sw[i]); sw[i] = (rgb[i]<=0 && sw[i]<0)? 0-sw[i]:((rgb[i]>=255 && sw[i]>255)? 0-sw[i]:sw[i]); rgb[i] += sw[i]; } // document.bgColor="#"+Mode16(rgb[0])+Mode16(rgb[1])+Mode16(rgb[2]); document.body.style.backgroundColor = "#"+Mode16(rgb[0])+Mode16(rgb[1])+Mode16(rgb[2]); if (timer_is_set) clearTimeout(timer_ID); timer_ID=setTimeout("chg_bg_color()",200); Timer_is_set=true; } </script> </head> <body onLoad="chg_bg_color()"> </body> </html>