Well, my code is working, but it's messy, if I try to organize it into functions it stops working:
How it works:
var navbar = document.getElementById('nav');
document.addEventListener("scroll", function() {
var posicaoy = window.pageYOffset;
console.log(posicaoy);
navbar.style.backgroundColor = posicaoy == 0 ? "transparent" : "white";
//outras coisas aqui...
});
This does not work:
var navbar = document.getElementById('nav');
document.addEventListener("scroll", function() {
var posicaoy = window.pageYOffset;
console.log(posicaoy);
function mudaNav(){
navbar.style.backgroundColor = posicaoy == 0 ? "transparent" : "white";
}
function mudabla1(){
//Codigo aqui
}
function mudabla2(){
//Codigo aqui
}
});