Skip to content

Instantly share code, notes, and snippets.

@r4fx
Created March 10, 2015 12:33
Show Gist options
  • Save r4fx/f47a3c0e232cb8097c1c to your computer and use it in GitHub Desktop.
Save r4fx/f47a3c0e232cb8097c1c to your computer and use it in GitHub Desktop.
Scroll events performance
// Resource https://medium.com/@mariusc23/hide-header-on-scroll-down-show-on-scroll-up-67bbaae9a78c
var scrollValInit = 200;
var didScroll;
$(window).scroll(function () {
didScroll = true;
});
setInterval(function () {
if (didScroll) {
hasScrolled();
didScroll = false;
}
}, 250);
function hasScrolled() {
var $scrollTopVal = $(this).scrollTop();
if ($scrollTopVal > scrollValInit) {
$btnToTop.addClass('active');
} else {
$btnToTop.removeClass('active');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment