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


/ Published in: JavaScript
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.