feat(ui): 重做页面转场为推入式,旧页面下沉、新页面从屏幕外滑入
原先的「滑入」只是 translateX(40px),几十像素的位移,在 1280px 宽的
屏上几乎看不出来,不是真正的页面转场。
现改为两段协同的推入效果:
1. 新页面(.page-slide)从屏幕外整体滑入:translateX(100%) → 0,
同时 scale 0.94 → 1、opacity 0 → 1。用百分比而非固定像素,
任何视口宽度下都从边缘之外开始。
2. 旧内容(#app)留在原位下沉:scale 1 → 0.94、右移 4%,
并叠加一层暗色遮罩(#app::after,opacity 0 → 1)。
关键改动:#app 不再被 display:none 直接隐藏——那样根本没有动画可做。
现由 body.page-stack-open 与 .page-stack-sink 控制下沉,转场结束后
才清理状态。相关逻辑抽成 sinkBackground / riseBackground / showSlide /
hideSlide 四个函数,供 switchPage、showPostPage、showUserPage、
showCustomPage 共用。返回按钮走 navigateBackToFeed,与浏览器后退键
方向一致(新页面向左滑出、首页上浮)。
过程中修掉两个真实问题:
- 样式表靠后位置本有一条 `#app { animation: fadeIn ... }`(交互动效层)。
ID 选择器优先级高于类选择器,导致最初的 .page-stack-sink 完全不生效,
实测首页 transform 始终为 none。改为 #app.page-stack-sink 组合选择器
后正常。reduced-motion 分支同样需要组合选择器才能压过它。
- app.js 中 showCustomPage 仍保留旧的 `#app.style.display = 'none'`,
且给容器写了内联 display,会覆盖转场所需的 display 切换。已一并移除。
实测(Puppeteer 逐帧采样,视口 1280×900):
- 新页面 X 坐标:1280 → 860 → 541 → 421 → 326 → 60 → 6 → 0,
起始 1280 恰好等于视口宽度,确认从屏幕外开始
- 首页:scale 1 → 0.940,右移 0 → 48px,遮罩不透明度 0 → 1.00
- 中间帧截图可见新页面自右侧滑入、旧页面在背景中缩小变暗
完整测试套件 25/25 通过。
This commit is contained in:
1 parent
0ea921186a
commit
7176bea12c
4 files changed
+297
-92
No files matched your search
+9
-12
@@ -78,19 +78,16 @@ async function renderUserProfile(username) {
|
||||
}
|
||||
|
||||
function showUserPage(username) {
|
||||
document.getElementById('app').style.display = 'none';
|
||||
document.querySelectorAll('.page-slide').forEach(el => {
|
||||
el.classList.remove('active', 'slide-out', 'slide-back');
|
||||
});
|
||||
const goingBack = typeof window.isNavigatingBack === 'function' && window.isNavigatingBack();
|
||||
const el = document.getElementById('pageUser');
|
||||
// 后退导航时用反向滑入,与主动进入区分
|
||||
if (typeof window.isNavigatingBack === 'function' && window.isNavigatingBack()) {
|
||||
el.classList.add('slide-back');
|
||||
}
|
||||
el.classList.add('active');
|
||||
el.style.animation = 'none';
|
||||
void el.offsetHeight;
|
||||
el.style.animation = '';
|
||||
|
||||
// 先让其他覆盖页滑出(例如从帖子详情跳到用户主页)
|
||||
document.querySelectorAll('.page-slide.active').forEach(other => {
|
||||
if (other !== el) hideSlide(other, { back: goingBack });
|
||||
});
|
||||
|
||||
// 首页留在背景中下沉,新页面从屏幕外滑入
|
||||
showSlide(el, { back: goingBack });
|
||||
currentPage = 'user';
|
||||
renderUserProfile(username);
|
||||
}
|
||||
Reference in new issue
Block a user