Skip to content

Instantly share code, notes, and snippets.

@amalichev
Last active June 22, 2018 06:17
Show Gist options
  • Save amalichev/12a791b2e7a582d89b1f684b718627b1 to your computer and use it in GitHub Desktop.
Save amalichev/12a791b2e7a582d89b1f684b718627b1 to your computer and use it in GitHub Desktop.
Scroll to content (jQuery)
// scroll to content button
var $scrollToContentBtn = $('.js-scroll-to-content'),
allowScrolling = true;
allowAutoScrolling = $(window).scrollTop() === 0;
$(window).scroll(function () {
var $this = $(this);
if ($this.scrollTop() > 0 && allowAutoScrolling) {
$('html, body').animate({
scrollTop: $this.height()
}, 'slow');
}
allowAutoScrolling = $this.scrollTop() === 0;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment