Skip to content

Commit

Permalink
fix(post-bottom-bar): show and hide post bottom bar using the scrolli…
Browse files Browse the repository at this point in the history
…ng delta

closes #498
  • Loading branch information
LouisBarranqueiro committed Jul 30, 2018
1 parent 573ba4b commit c9a0412
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions source/_js/post-bottom-bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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;
}
};
Expand Down

0 comments on commit c9a0412

Please sign in to comment.