Last active
November 4, 2023 09:01
-
-
Save emiremiroglu/f9020a8ae6d5cf758b3605aefec42d51 to your computer and use it in GitHub Desktop.
Add class on scroll vanilla.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
let scrollPosition = window.scrollY; | |
let header = document.querySelector('header'); | |
window.addEventListener('scroll', function () { | |
scrollPosition = window.scrollY; | |
if (scrollPosition >= 30) { | |
header.classList.add('scrolled'); | |
} else { | |
header.classList.remove('scrolled'); | |
} | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment