Last active
January 3, 2017 03:26
-
-
Save jsonberry/d6083c49860004b88cc1204ba8795bb7 to your computer and use it in GitHub Desktop.
Toggle Footer [jQuery 1.12+ && debouncing]
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
// 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