Can someone help me with changing the background image on my webpage's body when it has been scrolled past a certain point? I've managed to make the initial change, but when scrolling back up, the first background image is still replaced. Being new to JavaScript, any guidance on this would be greatly appreciated!
function changeBackground () {
var body = document.querySelector("body");
if (this.scrollY > 1000) {
document.body.style.backgroundImage = "url(../../../img/upa/landing/images/bg.jpg)";
} else {
document.body.style.backgroundImage = "url(../../../img/upa/landing/images/bg-2.jpg)";
}
}
window.addEventListener("scroll", changeBackground , false);