Dave
Dave

Reputation: 2018

Class won't toggle on scroll

Can someone assist me with this? Whenever I try to scroll, the class none doesn't toggle..

    window.addEventListener('scroll', function() {
    var header = document.getElementsById("here");
    header.classList.toggle("none", window.scrollY > 0);
});
.none {
    display: none;
}
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/b/b6/Image_created_with_a_mobile_phone.png/800px-Image_created_with_a_mobile_phone.png" id="here>

Upvotes: 0

Views: 45

Answers (1)

Simone Rossaini
Simone Rossaini

Reputation: 8162

You simple didn't close id of img and write elementsbyid instead of elementbyid.

window.addEventListener('scroll', function() {
    var header = document.getElementById("here");
    header.classList.toggle("none", window.scrollY > 0);
});
.none {
    display: none;
}
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/b/b6/Image_created_with_a_mobile_phone.png/800px-Image_created_with_a_mobile_phone.png" id="here">

Upvotes: 1

Related Questions