mirror of
https://github.com/aljazceru/awesome-nostr.git
synced 2025-02-22 06:39:00 +00:00
more familiar mobile touch XP
This commit is contained in:
parent
1324975ec0
commit
82c34be52b
83
script.js
83
script.js
@ -6,6 +6,8 @@ const body = document.body;
|
||||
let touchStartX = 0;
|
||||
let touchEndX = 0;
|
||||
let touchStartY = 0;
|
||||
let touchEndY = 0;
|
||||
let isSwiping = false;
|
||||
|
||||
// Color theme definitions
|
||||
const colorThemes = {
|
||||
@ -206,6 +208,87 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
Error loading content: ${error.message}
|
||||
</div>`;
|
||||
});
|
||||
|
||||
// Enhanced touch handling for sidebar
|
||||
touchStartX = 0;
|
||||
touchStartY = 0;
|
||||
touchEndX = 0;
|
||||
touchEndY = 0;
|
||||
isSwiping = false;
|
||||
|
||||
// Track touch movements
|
||||
document.addEventListener('touchstart', (e) => {
|
||||
touchStartX = e.touches[0].clientX;
|
||||
touchStartY = e.touches[0].clientY;
|
||||
isSwiping = true;
|
||||
}, { passive: true });
|
||||
|
||||
document.addEventListener('touchmove', (e) => {
|
||||
if (!isSwiping) return;
|
||||
|
||||
touchEndX = e.touches[0].clientX;
|
||||
touchEndY = e.touches[0].clientY;
|
||||
|
||||
// Calculate vertical and horizontal distance
|
||||
const deltaX = touchStartX - touchEndX;
|
||||
const deltaY = Math.abs(touchStartY - touchEndY);
|
||||
|
||||
// If vertical scrolling is more prominent, don't handle swipe
|
||||
if (deltaY > Math.abs(deltaX)) {
|
||||
isSwiping = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// Prevent default only if horizontal swipe is significant
|
||||
if (Math.abs(deltaX) > 10) {
|
||||
e.preventDefault();
|
||||
}
|
||||
}, { passive: false });
|
||||
|
||||
document.addEventListener('touchend', () => {
|
||||
if (!isSwiping) return;
|
||||
|
||||
const deltaX = touchStartX - touchEndX;
|
||||
const deltaY = Math.abs(touchStartY - touchEndY);
|
||||
const swipeThreshold = 50;
|
||||
|
||||
// Only handle horizontal swipes
|
||||
if (Math.abs(deltaX) > swipeThreshold && deltaY < 100) {
|
||||
if (deltaX > 0) {
|
||||
// Swipe left - close sidebar
|
||||
sidebar.classList.remove('active');
|
||||
} else {
|
||||
// Swipe right - open sidebar
|
||||
sidebar.classList.add('active');
|
||||
}
|
||||
}
|
||||
|
||||
isSwiping = false;
|
||||
}, { passive: true });
|
||||
|
||||
// Update sidebar link click handling
|
||||
document.querySelectorAll('.nav-links a').forEach(link => {
|
||||
link.addEventListener('click', (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
// Remove active class from all links
|
||||
document.querySelectorAll('.nav-links a').forEach(l =>
|
||||
l.classList.remove('active')
|
||||
);
|
||||
|
||||
// Add active class to clicked link
|
||||
link.classList.add('active');
|
||||
|
||||
// Get section name and display it
|
||||
const section = link.getAttribute('data-section');
|
||||
displaySection(section, window.parsedResources);
|
||||
|
||||
// Close sidebar on mobile
|
||||
if (window.innerWidth <= 768) {
|
||||
sidebar.classList.remove('active');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Helper function to update dark mode icon
|
||||
|
32
styles.css
32
styles.css
@ -51,9 +51,10 @@ body {
|
||||
border-right: 1px solid rgba(110, 84, 148, 0.15);
|
||||
box-shadow: 2px 0 8px rgba(0, 0, 0, 0.05);
|
||||
top: 60px; /* Start below top nav */
|
||||
touch-action: pan-y;
|
||||
touch-action: pan-y pinch-zoom;
|
||||
will-change: transform;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
overscroll-behavior: contain;
|
||||
}
|
||||
|
||||
.sidebar-header {
|
||||
@ -161,6 +162,8 @@ body {
|
||||
min-height: 100vh;
|
||||
overflow: auto;
|
||||
margin-top: 0;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
overscroll-behavior: contain;
|
||||
}
|
||||
|
||||
.content-header {
|
||||
@ -299,6 +302,33 @@ body {
|
||||
max-width: none;
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
|
||||
.nav-links a {
|
||||
padding: 0.75rem 1rem; /* Larger touch target */
|
||||
min-height: 44px; /* iOS recommended minimum */
|
||||
}
|
||||
|
||||
.theme-toggle,
|
||||
.menu-toggle {
|
||||
min-width: 44px;
|
||||
min-height: 44px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
/* Improve search input touch target */
|
||||
.search-box input {
|
||||
min-height: 44px;
|
||||
}
|
||||
|
||||
/* Add active state styles for touch feedback */
|
||||
.nav-links a:active,
|
||||
.theme-toggle:active,
|
||||
.menu-toggle:active {
|
||||
opacity: 0.7;
|
||||
transition: opacity 0.1s;
|
||||
}
|
||||
}
|
||||
|
||||
.markdown-content {
|
||||
|
Loading…
Reference in New Issue
Block a user