Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@poudelmadhav
Created September 22, 2018 18:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save poudelmadhav/2dc591b1d120d0b2cd35e92d8f385506 to your computer and use it in GitHub Desktop.
Save poudelmadhav/2dc591b1d120d0b2cd35e92d8f385506 to your computer and use it in GitHub Desktop.
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