Created
February 2, 2015 16:32
-
-
Save klamping/fd2d9d53ffd550c39cf9 to your computer and use it in GitHub Desktop.
Scroll thingy
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
// 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