Skip to content

Instantly share code, notes, and snippets.

@3014zhangshuo
Created February 23, 2017 07:01
Show Gist options
  • Save 3014zhangshuo/d96ea76aebc6157bfa6c7493d9648540 to your computer and use it in GitHub Desktop.
Save 3014zhangshuo/d96ea76aebc6157bfa6c7493d9648540 to your computer and use it in GitHub Desktop.
scroll button faq
(function($) {
var element = $('#faq'),
originalY = element.offset().top;
// Space between element and top of screen (when scrolling)
var topMargin = 500;
// Should probably be set in CSS; but here just for emphasis
element.css('position', 'relative');
$(window).on('scroll', function(event) {
var scrollTop = $(window).scrollTop();
element.stop(false, false).animate({
top: scrollTop < originalY
? 0
: scrollTop - originalY + topMargin
}, 200);
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment