Skip to content

Instantly share code, notes, and snippets.

@nikola-wd
Created August 5, 2019 00:11
Show Gist options
  • Select an option

  • Save nikola-wd/a5f32ac0b2b02916ad8519de02ea546c to your computer and use it in GitHub Desktop.

Select an option

Save nikola-wd/a5f32ac0b2b02916ad8519de02ea546c to your computer and use it in GitHub Desktop.
[Fixed Header onScroll] - Header get's class when scrolled #ui #sass #scss #code_bundles #header
const _headerFN = () => {
const $header = document.querySelector('.header');
const scrollTop = window.scrollY,
offsetTop = 60;
if (scrollTop >= offsetTop && window.innerWidth > 767) {
$header.classList.add('jsOnScroll');
document.body.classList.add('jsOnScroll-header');
} else {
$header.classList.remove('jsOnScroll');
document.body.classList.remove('jsOnScroll-header');
}
}
export default _headerFN;
.header {
&.jsOnScroll {
// Add code here
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment