0
Guys, my code is working, only it’s messy, if I try to organize in functions it stops working:
That’s 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...
});
So it doesn’t 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
}
});
Very good, I’ll check, I’m working with many global scopes, I need to adjust this.
– Tiago Silveira
if you’re using jQuery, try using custom plugins
– gpupo
I’m using pure js, I was getting too dependent on Jquery, but obg by tip.
– Tiago Silveira