diff options
Diffstat (limited to 'src/js/post-bottom-bar.js')
-rwxr-xr-x | src/js/post-bottom-bar.js | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/src/js/post-bottom-bar.js b/src/js/post-bottom-bar.js index 20fd5e9..b6d0c13 100755 --- a/src/js/post-bottom-bar.js +++ b/src/js/post-bottom-bar.js @@ -12,8 +12,10 @@ this.$postBottomBar = $('.post-bottom-bar'); this.$postFooter = $('.post-actions-wrap'); this.$header = $('#header'); - this.delta = 1; + this.delta = 15; this.lastScrollTop = 0; + this.lastScrollDownPos = 0; + this.lastScrollUpPos = 0; }; PostBottomBar.prototype = { @@ -47,17 +49,26 @@ swipePostBottomBar: function() { var scrollTop = $(window).scrollTop(); var postFooterOffsetTop = this.$postFooter.offset().top; - // show bottom bar - // if the user scrolled upwards more than `delta` - // and `post-footer` div isn't visible - if (this.lastScrollTop > scrollTop && - (postFooterOffsetTop + this.$postFooter.height() > scrollTop + $(window).height() || - postFooterOffsetTop < scrollTop + this.$header.height())) { - this.$postBottomBar.slideDown(); + + // scrolling up + if (this.lastScrollTop > scrollTop) { + // show bottom bar + // if the user scrolled upwards more than `delta` + // and `post-footer` div isn't visible + if (Math.abs(this.lastScrollDownPos - scrollTop) > this.delta && + (postFooterOffsetTop + this.$postFooter.height() > scrollTop + $(window).height() || + postFooterOffsetTop < scrollTop + this.$header.height())) { + this.$postBottomBar.slideDown(); + this.lastScrollUpPos = scrollTop; + } } - else { + + // scrolling down + if (scrollTop > this.lastScrollUpPos + this.delta) { this.$postBottomBar.slideUp(); + this.lastScrollDownPos = scrollTop; } + this.lastScrollTop = scrollTop; } }; |