[英]Class won't toggle on scroll
有人可以幫我嗎? 每當我嘗試滾動時,class none 都不會切換。
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>
您只是簡單地沒有關閉 img 的 id 並編寫elementsbyid
而不是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">
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.