Skip to content

Instantly share code, notes, and snippets.

@jsonberry
Last active January 3, 2017 03:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsonberry/d6083c49860004b88cc1204ba8795bb7 to your computer and use it in GitHub Desktop.
Save jsonberry/d6083c49860004b88cc1204ba8795bb7 to your computer and use it in GitHub Desktop.
Toggle Footer [jQuery 1.12+ && debouncing]
// jQuery 1.12+
// Bind to window scrolling and setup debouncer
$(window).scroll(function() {
clearTimeout(this.id);
this.id = setTimeout(doneScrolling, 130); // 130ms was the shortest time that allowed execution of only once, any slower and it would fire multiple times
});
// Execute any functions here when scrolling stops
// Put all the things here!
function doneScrolling(){
footerToggle();
};
function footerToggle(){
$(window).scrollTop() === $(document).height() - $(window).height() ? // Are we at the bottom of the page?
$('footer').fadeIn() : // Yes, fade the footer in
$('footer').fadeOut(); // No, fade the footer out
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment