We Recommend

Pro JavaScript Techniques Pro JavaScript Techniques
Pro JavaScript Techniques is the ultimate JavaScript book for the modern web developer. It provides everything you need to know about modern JavaScript, and shows what JavaScript can do for your web sites. This book doesn't waste any time looking at things you already know, like basic syntax and structures.


Posted By

fjm on 07/10/07


Tagged

css javascript tips


Versions (?)


[JavaScript] 時間帯によって、CSSを切り替える。


Published in: JavaScript 


時間帯によって、CSSを切り替える。

  1. <SCRIPT LANGUAGE="JavaScript">
  2. <!-- Begin
  3. function getCSS()
  4. {
  5. datetoday = new Date();
  6. timenow=datetoday.getTime();
  7. datetoday.setTime(timenow);
  8. thehour = datetoday.getHours();
  9.  
  10. if (thehour > 20)
  11. display = "tree_twilight.css";
  12. else if (thehour > 17)
  13. display = "tree_sunset.css";
  14. else if (thehour > 14)
  15. display = "tree_afternoon.css";
  16. else if (thehour > 11)
  17. display = "tree_noon.css";
  18. else if (thehour > 7)
  19. display = "tree_morning.css";
  20. else if (thehour > 4)
  21. display = "tree_sunrise.css";
  22. else if (thehour > 1)
  23. display = "tree_twilight.css";
  24. else
  25. display = "tree_sunset.css";
  26.  
  27. var css = '<'; css+='link rel="stylesheet" href=' + display + ' \/'; css+='>';
  28.  
  29. document.write(css);
  30. // End -->
  31. }
  32. </script>
  33. <script language="javascript">getCSS();</script>

Report this snippet 

You need to login to post a comment.