Created
February 23, 2017 07:01
-
-
Save 3014zhangshuo/d96ea76aebc6157bfa6c7493d9648540 to your computer and use it in GitHub Desktop.
scroll button faq
This file contains hidden or 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
(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