ciao ragazzi, avevo bisigno di cambiare il colore del DIV in base a diverse fasce orarie.
ho trovato uno script che funziona, che mi permette di cambiare il colore del DIV ma solo con le ore e non con i minuti, avrei bisogno di specificare anche i minuti, qualcuno può gentilmente aiutarmi.
codice HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test colore div - fasce ore</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<style>
.timeofday-bg {
width: 60%;
margin: 50px auto;
padding: 20px;
}
.morning-bg {
background-color: rgb(238, 229, 21);
}
.daylight-bg {
background-color: rgb(58, 226, 16);
}
.evening-bg {
background-color: rgb(221, 79, 34);
}
.twilight-bg {
background-color: rgb(69, 123, 192);
}
</style>
<!-- jquery change color of div each hour -->
<script type="text/javascript">
$(document).ready(function() {
var h = new Date().getHours();
/* var m = new Date().getMinutes(); */
var divs = $('.timeofday-bg');
if (h >= 6 && h < 12) {
divs.addClass('morning-bg');
} else if (h >= 12 && h < 18) {
divs.addClass('daylight-bg');
} else if (h >= 18 && h < 24) {
divs.addClass('evening-bg');
} else if (h >= 0 && h < 6) {
divs.addClass('twilight-bg');
}
});
</script>
</head>
<body>
<div class="timeofday-bg">
test, cambio colore DIV in base a fasce orarie.
</div>
</body>
</html>
grazie in anticipo.
ciao