Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Change Body Background Every 10 sec

  • This topic is empty.
Viewing 4 posts - 16 through 19 (of 19 total)
  • Author
    Posts
  • #279755
    docwest
    Participant

    Rather then 10 seconds how about 24 hours a new background.

    #279757
    Shikkediel
    Participant

    I think that would either have to be coded server side (in case the page is not served with only HTML but is inserted with PHP for example) or if you want an approach on the user’s end, you could go with window.localStorage and check the last time the page was visited – if that was more than a day ago, then change the background.

    #280907
    sagarleo1
    Participant

    Hii, I have given you the code (JavaScript), try it yourself and share the result

    var i = 0;
    function change() {
    var doc = document.getElementById(“background”);
    var color = [“black”, “blue”, “brown”, “green”];
    doc.style.backgroundColor = color[i];
    i = (i + 1) % color.length;
    }
    setInterval(change, 1000);

    &nbsp
    #283553
    hhalter
    Participant

    This is awesome! I need some help adding a sliding transition for each image. I don’t like how it just flashes to the next image.

    Thanks!

Viewing 4 posts - 16 through 19 (of 19 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.