Reputation:
I'm experimenting with something new in Javascript.
I would like to change the background color of an item when the scrollY
position has reached a specific value; 80 in this case. However, it's not working. Is there something wrong with the logic?
window.addEventListener("scroll", function (event){
var scroll = this.scrollY;
if scroll.value === '80' {
document.getElementById="Gegevens".style.background-color="lightblue" } else {}
})
Upvotes: 0
Views: 37
Reputation: 8368
There are a number of errors in your code:
if
conditionscroll.value
getElementById
needs brackets not an equals signbackground-color
event
as a parameter when using this
(not an error but interesting either way)This is how it should be:
window.addEventListener("scroll", function(event) {
const scroll = this.scrollY;
if (scroll >= 80)
document.getElementById("Gegevens").style.backgroundColor="lightblue"
})
Upvotes: 1