I'm trying to make my background change during the day depending on the time, tried 4 different methods and searched here, but still can't figure it out. Can anybody tell me what i'm doing wrong? Thanks in advance!
$(document).ready(function(){
var d = new Date();
var n = d.getHours();
if (n > 6 || n < 10)
$(body).addClass('two');
else if (n > 10 && n < 17)
$(body).addClass('one');
else if (n > 17 && n <= 19)
$(body).addClass('three');
else
$(body).addClass('five');
});
CSS
.one{
background-image: linear-gradient(-179deg, #8EB39E 0%, #CEBD95 26%, #DBBF94 33%, #D48B7A 67%, #8B374E 100%);}
.two{
background-image: linear-gradient(-180deg, #FFEC96 0%, #92C684 65%, #185C34 100%);}
.three{
background-image: linear-gradient(-180deg, #FFEC96 0%, #92C684 65%, #185C34 100%);}
.five{
background-image: linear-gradient(0deg, #FAF2D8 0%, #F0CCB7 20%, #7F9993 46%, #1E6D74 69%, #0B3134 93%);}`
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…