Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
172 views
Welcome To Ask or Share your Answers For Others

1 Answer

If you meant the html body tag, then wrap body in quotes like you would with any CSS Selector. In your case $("body").addClass("two");, otherwise jQuery will treat it as a variable.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...