Last active
May 7, 2017 19:24
-
-
Save lmosele/498aea0de319176c86fe56376606c82d to your computer and use it in GitHub Desktop.
just a stupid simple jquery thing for styles on scroll
This file contains 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
// This simple jquery script adds a class to an element once it reaches the bottom of a container (for example, a navbar switching colors once it reaches a new section on the page | |
$(window).scroll(function() { | |
var scroll = $(window).scrollTop(); | |
var topofDiv = $(".banner").offset().top; //use the element you want to limit the styles to | |
var height = $(".banner").outerHeight(); | |
if (scroll >= (topofDiv + height) - 80) { // the -80 should be the height of the container that's changing | |
$("#topNav").addClass("scrolled"); // this is where you add the new class for the element you want to change | |
} else { | |
$("#topNav").removeClass("scrolled"); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment