Hello i want to target the opacity of divs when the user scrolls down and remove it when he scrolls up again.That's the code i got so far.It works but i don't understand why i have to loop through it again in the esle condition or is their a better way of doing it.Pls only javascript no jquery.thank's alot.
window.addEventListener('scroll',visible);
function visible(){
if(window.pageYOffset>2000){
var x = document.getElementById('wrapper').querySelectorAll('.div');
i = 0;
for (var i = 0 ; x.length >i; i++) {
x[i].style.opacity = "1";
x[i].style.transition = " 1s ease 0s ";
}
}else{
var x = document.getElementById('wrapper').querySelectorAll('.div');
i = 0;
for (var i = 0 ; x.length >i; i++) {
x[i].style.opacity = "0";
x[i].style.transition = " 1s ease 0s ";
}
}
}
querySelectorAll()returns a list of the element hence you need to iterate