Prova.
Codice PHP:
<!DOCTYPE html>
<html>
<head>
<style>
.chiuso {
width: 200px;
height: 200px;
background-color: red;
}
.aperto {
width: 200px;
height: 200px;
background-color: green;
}
</style>
<script language="javascript" type="text/javascript">
<!--
rangeChiuso = new Array("0000-0559","1200-1359","1900-2359");
function isClosed(h, aRange) {
sLL = aRange.substr(0,4);
sUL = aRange.substr(5,4);
aLL = parseInt(sLL);
aUL = parseInt(sUL);
//alert(aLL + " " + aUL);
if (aLL <= h && h <= aUL) {
return true;
} else {
return false;
}
}
function pippo(){
var data=new Date();
var h = data.getHours() * 100 + data.getMinutes();
max = rangeChiuso.length - 1;
chiuso = false;
for (i=0;i<=max;i++) {
if (isClosed(h,rangeChiuso[i])) {
chiuso = true;
i = max + 10;
}
}
if (chiuso) {
document.getElementById("centro").className = "chiuso";
document.getElementById("centro").innerText = 'chiuso';
} else {
document.getElementById('centro').className = 'aperto';
document.getElementById('centro').innerText = 'aperto';
}
}
//-->
</script>
</head>
<body>
<div id="centro" class="centro1" >ciao ti vedo</div>
<script language="javascript" type="text/javascript">
setInterval("pippo()",1000);
// pippo();
</script>
</body>
</html>