Add swipe navigation for calendar month view
- Implemented touch event listeners to allow users to swipe left or right on the calendar for month navigation. - Added a swipe threshold to prevent accidental navigation and ensure smooth user experience. - Updated CSS to enable touch actions for better responsiveness on touch devices.
This commit is contained in:
@@ -536,6 +536,37 @@
|
||||
loadMonth();
|
||||
});
|
||||
|
||||
(function bindSwipeMonth() {
|
||||
var swipeEl = document.getElementById("calendarSticky");
|
||||
if (!swipeEl) return;
|
||||
var startX = 0;
|
||||
var startY = 0;
|
||||
var SWIPE_THRESHOLD = 50;
|
||||
swipeEl.addEventListener("touchstart", function (e) {
|
||||
if (e.changedTouches.length === 0) return;
|
||||
var t = e.changedTouches[0];
|
||||
startX = t.clientX;
|
||||
startY = t.clientY;
|
||||
}, { passive: true });
|
||||
swipeEl.addEventListener("touchend", function (e) {
|
||||
if (e.changedTouches.length === 0) return;
|
||||
if (!accessDeniedEl.hidden) return;
|
||||
if (prevBtn.disabled) return;
|
||||
var t = e.changedTouches[0];
|
||||
var deltaX = t.clientX - startX;
|
||||
var deltaY = t.clientY - startY;
|
||||
if (Math.abs(deltaX) <= SWIPE_THRESHOLD) return;
|
||||
if (Math.abs(deltaY) > Math.abs(deltaX)) return;
|
||||
if (deltaX > SWIPE_THRESHOLD) {
|
||||
current.setMonth(current.getMonth() - 1);
|
||||
loadMonth();
|
||||
} else if (deltaX < -SWIPE_THRESHOLD) {
|
||||
current.setMonth(current.getMonth() + 1);
|
||||
loadMonth();
|
||||
}
|
||||
}, { passive: true });
|
||||
})();
|
||||
|
||||
function bindStickyScrollShadow() {
|
||||
var stickyEl = document.getElementById("calendarSticky");
|
||||
if (!stickyEl || document._stickyScrollBound) return;
|
||||
|
||||
@@ -80,6 +80,7 @@ body {
|
||||
background: var(--bg);
|
||||
padding-bottom: 12px;
|
||||
margin-bottom: 4px;
|
||||
touch-action: pan-y;
|
||||
}
|
||||
|
||||
.calendar-sticky.is-scrolled {
|
||||
|
||||
Reference in New Issue
Block a user