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
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