Skip to content

Instantly share code, notes, and snippets.

@sudarshanReddykurri
Last active September 11, 2016 05:35
Show Gist options
  • Save sudarshanReddykurri/1076562c6d12e36fe512e7b3e7a21ff0 to your computer and use it in GitHub Desktop.
Save sudarshanReddykurri/1076562c6d12e36fe512e7b3e7a21ff0 to your computer and use it in GitHub Desktop.
Code for on scroll background color change for the navigation in JQuery
<script>
$(document).ready(function(){
$(window).scroll(function() { // check if scroll event happened
if ($(document).scrollTop() > 50) { // check if user scrolled more than 50 from top of the browser window
$('.header').css("background-color", "#fff");// change background-color to white
} else {
$('.header').css("background-color", "#000"); // if not, change it back to black
}
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment