UX: Scroll-Position bleibt bei View-Refresh (Zeitraum-Chips), Body-Scroll-Lock bei offenen Sheets, Sheet-Drag folgt sauber dem Finger

This commit is contained in:
Duarte Santos committed 2026-07-18 23:01:20 +02:00
1 parent 8355c14901
commit b166e1aa45
4 files changed
+47 -19

No files matched your search

+40 -13
View File
@@ -252,6 +252,26 @@ function bindMediaToggle(media, ex) {
};
}
/* ---------- body scroll lock (iOS-safe) while a modal is open ---------- */
function currentScrollY() {
return 'slock' in document.body.dataset ? +document.body.dataset.slock : (window.scrollY || 0);
}
function lockBodyScroll() {
if ('slock' in document.body.dataset) return;
const y = window.scrollY || 0;
document.body.dataset.slock = y;
const st = document.body.style;
st.position = 'fixed'; st.top = -y + 'px'; st.left = '0'; st.right = '0'; st.width = '100%';
}
function unlockBodyScroll() {
if (!('slock' in document.body.dataset)) return;
const y = +document.body.dataset.slock;
delete document.body.dataset.slock;
const st = document.body.style;
st.position = st.top = st.left = st.right = st.width = '';
window.scrollTo(0, y);
}
/* ---------- modal system ---------- */
const modalRoot = $('#modal-root');
let modalStack = [];
@@ -260,10 +280,11 @@ function openModal(html, kind) {
wrap.innerHTML = `<div class="mback"></div><div class="${kind || 'sheet'}">${kind === 'center' ? '' : '<div class="grab"></div>'}${html}</div>`;
modalRoot.appendChild(wrap);
modalRoot.classList.add('open');
lockBodyScroll();
const close = () => {
wrap.remove();
modalStack = modalStack.filter(m => m !== api);
if (!modalRoot.children.length) modalRoot.classList.remove('open');
if (!modalRoot.children.length) { modalRoot.classList.remove('open'); unlockBodyScroll(); }
};
wrap.querySelector('.mback').addEventListener('click', () => { if (!wrap.dataset.lock) close(); });
const api = { el: wrap, close, lock: v => { wrap.dataset.lock = v ? '1' : ''; } };
@@ -279,10 +300,11 @@ function openModal(html, kind) {
if (startY === null) return;
delta = e.touches[0].clientY - startY;
if (delta > 0 && sh.scrollTop <= 0) {
e.preventDefault(); // only the sheet moves, never the page behind
sh.style.transition = 'none';
sh.style.transform = `translateY(${delta}px)`;
} else delta = 0;
}, { passive: true });
}, { passive: false });
sh.addEventListener('touchend', () => {
if (startY === null) return;
sh.style.transition = 'transform .2s';
@@ -466,22 +488,27 @@ function nav(hash) { location.hash = hash; }
function route() { renderView(); updateTabbar(); }
function renderView() {
const h = (location.hash || '#home').slice(1);
// re-rendering the same view (range chips, toggles, …) keeps the scroll position;
// only an actual view change jumps to the top
const sameView = renderView._last === h;
renderView._last = h;
const keepY = sameView ? currentScrollY() : 0;
const [view, ...rest] = h.split('/');
clearInterval(elapsedInt);
closeAllModals();
const app = $('#app');
window.scrollTo(0, 0);
if (!USER && !isGuest()) return viewLogin(app);
if (view === 'plan' && rest[0] === 'r') return viewRoutineEdit(app, rest[1]);
switch (view) {
case 'plan': return viewPlan(app);
case 'workout': return viewWorkout(app);
case 'stats': return viewStats(app);
case 'library': return viewLibrary(app);
case 'settings': return viewSettings(app);
case 'history': return viewHistory(app);
default: return viewHome(app);
if (!USER && !isGuest()) viewLogin(app);
else if (view === 'plan' && rest[0] === 'r') viewRoutineEdit(app, rest[1]);
else switch (view) {
case 'plan': viewPlan(app); break;
case 'workout': viewWorkout(app); break;
case 'stats': viewStats(app); break;
case 'library': viewLibrary(app); break;
case 'settings': viewSettings(app); break;
case 'history': viewHistory(app); break;
default: viewHome(app);
}
window.scrollTo(0, keepY);
}
window.addEventListener('hashchange', route);
document.querySelectorAll('#tabbar button').forEach(b => b.addEventListener('click', () => {
+3 -3
View File
@@ -13,7 +13,7 @@
<link rel="manifest" href="manifest.json">
<link rel="apple-touch-icon" href="icon-180.png">
<link rel="icon" type="image/png" href="icon-180.png">
<link rel="stylesheet" href="style.css?v=6">
<link rel="stylesheet" href="style.css?v=7">
</head>
<body>
<div id="app"><div style="padding-top:42vh;text-align:center;font-size:2.2rem">🏋️</div></div>
@@ -45,7 +45,7 @@
<div id="modal-root"></div>
<div id="toast"></div>
<script src="data.js?v=6"></script>
<script src="app.js?v=6"></script>
<script src="data.js?v=7"></script>
<script src="app.js?v=7"></script>
</body>
</html>
+2 -1
View File
@@ -152,7 +152,8 @@ a{color:var(--acc)}
/* ---------- modal ---------- */
#modal-root{position:fixed;inset:0;z-index:100;display:none}
#modal-root.open{display:block}
.mback{position:absolute;inset:0;background:rgba(0,0,0,.6);backdrop-filter:blur(3px)}
.mback{position:absolute;inset:0;background:rgba(0,0,0,.6);backdrop-filter:blur(3px);
touch-action:none;overscroll-behavior:none}
.sheet{position:absolute;left:0;right:0;bottom:0;background:var(--bg2);
border-radius:22px 22px 0 0;padding:10px 18px calc(22px + var(--sab));
max-height:88vh;overflow-y:auto;-webkit-overflow-scrolling:touch;animation:slideup .28s;
+2 -2
View File
@@ -1,6 +1,6 @@
/* GymLog service worker — network-first for app shell, cache-first for media */
const CACHE = 'gymlog-v6';
const SHELL = ['./', 'index.html', 'style.css?v=6', 'app.js?v=6', 'data.js?v=6', 'manifest.json'];
const CACHE = 'gymlog-v7';
const SHELL = ['./', 'index.html', 'style.css?v=7', 'app.js?v=7', 'data.js?v=7', 'manifest.json'];
self.addEventListener('install', e => {
e.waitUntil(caches.open(CACHE).then(c => c.addAll(SHELL)).then(() => self.skipWaiting()));