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

Home Forums JavaScript javascript change bg color when navbar hits top of screen

  • This topic is empty.
Viewing 1 post (of 1 total)
  • Author
  • #170634

    ok so i have a sticky nag named #sticky i want it to slowly change color when it gets stuck to the top of the browser…this is what i have:

    var bar = document.getElementById(“sticker”);
    var viewportOffset = bar.getBoundingClientRect();

    var top =;
    if(top == 0){ = "white";
    }else{ = "black";

    obi the top thing in the if statement isn’t right…im not sure how to get it to work

Viewing 1 post (of 1 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.