Skip to content

Instantly share code, notes, and snippets.

@charleslouis
Created September 22, 2018 07:47
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save charleslouis/8e4a8711f113d9d595f933f956d5ecf8 to your computer and use it in GitHub Desktop.
export function addClassToBodyOnscroll(elementReference) {
let timer;
const mainNav = $(elementReference);
const mainNavH = mainNav.outerHeight();
console.group('scrollTop');
console.log('mainNavH', mainNavH);
console.groupEnd();
$(window).scroll(function() {
if (timer) clearTimeout(timer);
timer = setTimeout(function() {
if (($(window).scrollTop()) < 2) {
$('body').removeClass('scrolled');
} else {
$('body').addClass('scrolled');
}
if (($(window).scrollTop()) < mainNavH) {
$('body').removeClass('scrolled-below-nav');
} else {
$('body').addClass('scrolled-below-nav');
}
}, 10);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment