Created
December 12, 2015 18:27
-
-
Save allusis/bbe5cc69105a6316805e to your computer and use it in GitHub Desktop.
Add CSS class on scroll
This file contains hidden or 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
$(function(){ | |
var shrinkHeader = 10; | |
$(window).scroll(function() { | |
var scroll = getCurrentScroll(); | |
if ( scroll >= shrinkHeader ) { | |
$('body').addClass('scrolled'); | |
} | |
else { | |
$('body').removeClass('scrolled'); | |
} | |
}); | |
function getCurrentScroll() { | |
return window.pageYOffset || document.documentElement.scrollTop; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment