Skip to content

Commit

Permalink
Add a draggable back-to-top button on side menu [Mobile]
Browse files Browse the repository at this point in the history
  • Loading branch information
gebederry committed Jul 28, 2024
1 parent 6a694db commit 6c4bd75
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion assets/js/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,11 @@ sideMenu.addEventListener('scroll', function () {
document.querySelector('.scroller-line-bt').style.display = atBottom ? '' : 'none';
document.querySelector('.scroller-arrow-bt').style.display = atBottom ? 'none' : '';

backToTop.classList.toggle('is-visible', this.scrollTop && this.scrollTop < lastScrollY);
if (this.scrollTop !== 0 && this.scrollTop < lastScrollY) {
backToTop.classList.add('is-visible');
} else if (this.scrollTop === 0 || this.scrollTop > lastScrollY) {
backToTop.classList.remove('is-visible');
}
lastScrollY = this.scrollTop;
});

Expand Down Expand Up @@ -1560,6 +1564,11 @@ function draggify(el, { storageKey }) {
document.addEventListener('pointerup', onDragEnd);
document.addEventListener('pointercancel', onDragEnd);

el.addEventListener('touchstart', onDragStart);
document.addEventListener('touchmove', onDragMove);
document.addEventListener('touchend', onDragEnd);
document.addEventListener('touchcancel', onDragEnd);

restorePosition();

return {
Expand Down

0 comments on commit 6c4bd75

Please sign in to comment.