Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Background color of navbar change on scroll
<div class="nav"></div>
<script>
window.onscroll = () => {
const nav = document.querySelector('.nav');
if(this.scrollY <= 500)
nav.style.backgroundColor = 'rgba(0,0,0,0)';
else
nav.style.backgroundColor = 'rgba(0,0,0,0.9)';
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.