Skip to content

Instantly share code, notes, and snippets.

@EastSideCode
Created April 10, 2018 13:14
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 EastSideCode/b2609da858c5cbbac71dd59239af36e5 to your computer and use it in GitHub Desktop.
Save EastSideCode/b2609da858c5cbbac71dd59239af36e5 to your computer and use it in GitHub Desktop.
Add a class to an element on page scroll
jQuery(window).scroll(function($) {
var scroll = $(window).scrollTop();
if (scroll >= 500) {
$(".element").addClass("sample-class-to-add");
} else {
$(".element").removeClass("sample-class-to-add");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment