v26110253 测试类页面记住最后停留的页面(开始/答题第几题/结果):生娃计算器、5 个专题测试、广场测一测
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -442,7 +442,20 @@ mark{background:linear-gradient(transparent 62%,var(--c20) 0);color:inherit;padd
|
||||
setTimeout(function () { el.classList.add('in'); }, 60 * n++);
|
||||
});
|
||||
}, { root: sc, threshold: .08 }) : null;
|
||||
/* 11-03 用户:「重新测试后退回首页,再进来还是结果页」→ 记住最后停在哪(开始 / 第几题 / 结果),再进来回到那里 */
|
||||
function pos(v) {
|
||||
if (v) pos.v = v;
|
||||
try { localStorage.setItem(KEY + '.pos', JSON.stringify({ v: pos.v, cur: cur, ans: ans })); } catch (e) {}
|
||||
}
|
||||
function resume() {
|
||||
var p = null; try { p = JSON.parse(localStorage.getItem(KEY + '.pos') || 'null'); } catch (e) {}
|
||||
if (!p) return false; /* 旧用户没有记录:照原来的(有结果看结果) */
|
||||
if (p.v === 'start') { show('start'); return true; }
|
||||
if (p.v === 'quiz' && Array.isArray(p.ans)) { cur = Math.max(0, Math.min(+p.cur || 0, QS.length - 1)); ans = p.ans.slice(0, QS.length); paint(); show('quiz'); return true; }
|
||||
return false;
|
||||
}
|
||||
function show(name) {
|
||||
pos(name);
|
||||
Object.keys(views).forEach(function (k) { views[k].classList.toggle('on', k === name); });
|
||||
sc.scrollTop = 0;
|
||||
[].forEach.call(views[name].querySelectorAll('.fade'), function (el) {
|
||||
@@ -469,6 +482,7 @@ mark{background:linear-gradient(transparent 62%,var(--c20) 0);color:inherit;padd
|
||||
'</span><span class="ck"><svg class="ic"><use href="#i-check" xlink:href="#i-check"/></svg></span></button>';
|
||||
}).join('');
|
||||
$('#prevBtn').disabled = cur === 0;
|
||||
if (pos.v === 'quiz') pos();
|
||||
}
|
||||
|
||||
/* 左右滑动:前进 → 当前向左滑出、新题从右滑入;上一题反过来 */
|
||||
@@ -760,7 +774,8 @@ mark{background:linear-gradient(transparent 62%,var(--c20) 0);color:inherit;padd
|
||||
/* 入口:有上次结果直接看结果,否则开始页 */
|
||||
var saved = null;
|
||||
try { saved = JSON.parse(localStorage.getItem(KEY) || 'null'); } catch (e) {}
|
||||
if (saved && TYPES[saved.type] && saved.scores && saved.ans && saved.ans.length === QS.length) render(saved, true);
|
||||
if (resume()) ;
|
||||
else if (saved && TYPES[saved.type] && saved.scores && saved.ans && saved.ans.length === QS.length) render(saved, true);
|
||||
else show('start');
|
||||
|
||||
/* 禁止下拉回弹:固定外壳 + 容器滚动 + 到顶/到底时拦 touchmove */
|
||||
|
||||
Reference in New Issue
Block a user