Created
March 10, 2015 12:33
-
-
Save r4fx/f47a3c0e232cb8097c1c to your computer and use it in GitHub Desktop.
Scroll events performance
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
// 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