Forums

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
    Posts
  • #170634
    rwchampin
    Participant

    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 = viewportOffset.top;
    if(top == 0){
        bar.style.backgroundColor = "white";
    }else{
        bar.style.backgroundColor = "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.