fix(ui): 修正滑动手势的两个确凿缺陷(触屏不切换 / 触控板方向反)
v89 实测 12/16,且已测出事件确实到达(触摸 touch+pointer 各 7 个、wheel deltaX=40 共 4 次), 证明不是"事件没到",而是逻辑把结果吃掉了: ① 防误触拦截器把自己吞了:滑动后 400ms 内抑制 click(防误开卡片), 而切换手势发的正是 tabs[j].click() → 被自己拦掉 → 表现为"滑了没反应"。 修法:程序化切换 click 期间置 swipeSelfClick 放行,并清掉本次抑制窗口。 ② 触控板方向反了:两指向左滑时浏览器给 deltaX > 0(内容右移), 原实现映射成"上一个",在第一个分组会被 clamp → 看起来完全没反应。 修法:deltaX > 0 → 下一个分组。
This commit is contained in:
11
web/navi.js
11
web/navi.js
@ -629,6 +629,7 @@
|
||||
let swipeEl = null; // 已绑定手势的 .minimal-home(元素重建时重绑)
|
||||
let swipeDocBound = false; // document 级监听只装一次
|
||||
let swipeBusy = false, swipeAcc = 0, swipeAccAt = 0, swipeCoolUntil = 0, swipeEatClick = 0;
|
||||
let swipeSelfClick = false; // 我们自己的切换 click 不能被自己的防误触拦掉
|
||||
|
||||
function swipeTabs() {
|
||||
return Array.from(document.querySelectorAll('.minimal-headings-row > .minimal-section-heading.headings'));
|
||||
@ -687,7 +688,11 @@
|
||||
frame.style.opacity = '0.28';
|
||||
await later(90);
|
||||
}
|
||||
tabs[j].click();
|
||||
// 关键:这是我们自己发起的切换 click —— 必须绕开"防误触"拦截,
|
||||
// 否则会出现"手势收到了、手势条件也满足,但页面没切"的怪象(实测踩过)。
|
||||
swipeEatClick = 0;
|
||||
swipeSelfClick = true;
|
||||
try { tabs[j].click(); } finally { swipeSelfClick = false; }
|
||||
await later(70);
|
||||
if (fade) {
|
||||
frame.style.transition = 'opacity 150ms ease';
|
||||
@ -752,7 +757,8 @@
|
||||
swipeAccAt = now;
|
||||
swipeAcc += evt.deltaX;
|
||||
if (Math.abs(swipeAcc) >= SWIPE.wheelShown && !swipeBusy && now >= swipeCoolUntil) {
|
||||
const dir = swipeAcc < 0 ? 1 : -1;
|
||||
// 方向语义实测:两指向左滑 → 浏览器给 deltaX > 0 → 应是"下一个分组"
|
||||
const dir = swipeAcc > 0 ? 1 : -1;
|
||||
swipeAcc = 0;
|
||||
swipeSwitch(dir);
|
||||
}
|
||||
@ -762,6 +768,7 @@
|
||||
swipeDocBound = true;
|
||||
// 滑动后吞掉紧随的一次 click,避免误开卡片里的链接
|
||||
document.addEventListener('click', (evt) => {
|
||||
if (swipeSelfClick) return; // 放行我们自己的切换 click
|
||||
if (Date.now() < swipeEatClick) {
|
||||
swipeEatClick = 0;
|
||||
evt.preventDefault();
|
||||
|
||||
Reference in New Issue
Block a user