From 6c4bd754e48ce0d223c957ec3d2e1a9d3a373cef Mon Sep 17 00:00:00 2001 From: gebederry Date: Sun, 28 Jul 2024 22:27:56 +0800 Subject: [PATCH] Add a draggable back-to-top button on side menu [Mobile] --- assets/js/scripts.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/assets/js/scripts.js b/assets/js/scripts.js index 725fac60c..df41a0e61 100644 --- a/assets/js/scripts.js +++ b/assets/js/scripts.js @@ -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; }); @@ -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 {