Click to See Complete Forum and Search --> : altering the look of a site during the day?


johnkai
12-30-2003, 10:29 AM
Hi, i'm trying to create a web site that dynamically brings in four different CSS throughout the day, one for early morning, midday, evening and night. I think this could be done using javascript can anybody help?

Pittimann
12-30-2003, 10:49 AM
Hi!

A very simple example just dealing with the background color of the document body:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script language="JavaScript" type="text/javascript">
<!--
var today=new Date();
var hour=today.getHours();
if (hour<=6){
document.write('<style>body{background-color: blue;}</style>');
}
if (hour>6&&hour<=12){
document.write('<style>body{background-color: red;}</style>');
}
if (hour>12&&hour<=18){
document.write('<style>body{background-color: gray;}</style>');
}
if (hour>18){
document.write('<style>body{background-color: lime;}</style>');
}
//-->
</script>
</head>
<body>
</body>
</html>

You could add more attributes or use external css files for each of the periods of time...

Cheers - Pit

zachzach
12-30-2003, 02:05 PM
you could do it with asp and make a super interactive one...
like show what it would display if you were in __ timezone
and it wouldn't be that hard