Skip to content

Instantly share code, notes, and snippets.

@klamping
Created February 2, 2015 16:32
Show Gist options
  • Save klamping/fd2d9d53ffd550c39cf9 to your computer and use it in GitHub Desktop.
Save klamping/fd2d9d53ffd550c39cf9 to your computer and use it in GitHub Desktop.
Scroll thingy
// Container element to add/remove class to
var container = $('body')
// this is the class that will be added to the body tag when the page is scrolled down
var scrollClass = "window-scrolled";
// how far down the page needs to be scrolled for the class to be added
var positionTrigger = 10;
$(window).scroll(function (event) {
// how far down the page is currently scrolled
var scroll = $(window).scrollTop();
// if we're farther down than our trigger, add the class
if (scroll > positionTrigger) {
container.addClass(scrollClass);
} else {
container.removeClass(scrollClass);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment