fix: smooth post title and card morph

This commit is contained in:
lezi-fun committed 2026-08-11 15:32:26 +08:00
1 parent 608e6b2522
commit ae2d5e82ca
3 files changed
+26 -25

No files matched your search

+1
View File
@@ -31,6 +31,7 @@ export async function GET(req) {
p.*, p.*,
u.username, u.username,
u.avatar_url, u.avatar_url,
u.signature,
(SELECT COUNT(*) FROM replies WHERE post_id = p.id) as reply_count (SELECT COUNT(*) FROM replies WHERE post_id = p.id) as reply_count
FROM posts p FROM posts p
JOIN users u ON p.user_id = u.id JOIN users u ON p.user_id = u.id
+23 -11
View File
@@ -920,6 +920,13 @@ html.home-view-transition.returning-home #pagePost .post-page-header h2 {
view-transition-name: post-heading; view-transition-name: post-heading;
} }
html.post-view-transition .post-card .post-title,
html.home-view-transition.returning-home .post-card .post-title {
display: block;
width: max-content;
max-width: 100%;
}
html.post-view-transition::view-transition, html.post-view-transition::view-transition,
html.home-view-transition::view-transition { html.home-view-transition::view-transition {
background: linear-gradient(145deg, var(--bg-start) 0%, var(--bg-end) 100%); background: linear-gradient(145deg, var(--bg-start) 0%, var(--bg-end) 100%);
@@ -930,12 +937,16 @@ html.post-view-transition::view-transition-group(post-expand) {
animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1); animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
} }
html.post-view-transition::view-transition-group(post-sidebar), html.post-view-transition::view-transition-group(post-sidebar) {
html.post-view-transition::view-transition-group(post-heading) {
animation-duration: 0.72s; animation-duration: 0.72s;
animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1); animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
} }
html.post-view-transition::view-transition-group(post-heading) {
animation-duration: 0.64s;
animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
}
html.post-view-transition::view-transition-group(post-time) { html.post-view-transition::view-transition-group(post-time) {
animation-duration: 1.05s; animation-duration: 1.05s;
animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1); animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
@@ -968,11 +979,11 @@ html.post-view-transition::view-transition-new(post-expand) {
} }
html.post-view-transition::view-transition-old(post-heading) { html.post-view-transition::view-transition-old(post-heading) {
animation: sharedTitleOut 0.14s 0.48s ease-out both; animation: sharedTitleMorphOut 0.64s ease-out both;
} }
html.post-view-transition::view-transition-new(post-heading) { html.post-view-transition::view-transition-new(post-heading) {
animation: sharedTitleIn 0.14s 0.82s ease-out both; animation: sharedTitleMorphIn 0.64s ease-out both;
} }
html.post-view-transition::view-transition-old(post-time) { html.post-view-transition::view-transition-old(post-time) {
@@ -1028,11 +1039,11 @@ html.home-view-transition.returning-home::view-transition-new(post-expand) {
} }
html.home-view-transition.returning-home::view-transition-old(post-heading) { html.home-view-transition.returning-home::view-transition-old(post-heading) {
animation: sharedTitleOut 0.12s 0.22s ease-out both; animation: sharedTitleMorphOut 0.42s ease-out both;
} }
html.home-view-transition.returning-home::view-transition-new(post-heading) { html.home-view-transition.returning-home::view-transition-new(post-heading) {
animation: sharedTitleIn 0.12s 0.36s ease-out both; animation: sharedTitleMorphIn 0.42s ease-out both;
} }
html.home-view-transition.returning-home::view-transition-old(post-time), html.home-view-transition.returning-home::view-transition-old(post-time),
@@ -1082,13 +1093,14 @@ html.home-view-transition.returning-home::view-transition-new(post-sidebar) {
to { opacity: 1; } to { opacity: 1; }
} }
@keyframes sharedTitleOut { @keyframes sharedTitleMorphOut {
to { opacity: 0; } 0%, 68% { opacity: 1; }
100% { opacity: 0; }
} }
@keyframes sharedTitleIn { @keyframes sharedTitleMorphIn {
from { opacity: 0; } 0%, 62% { opacity: 0; }
to { opacity: 1; } 100% { opacity: 1; }
} }
@keyframes sharedTimeOut { @keyframes sharedTimeOut {
+2 -14
View File
@@ -7,7 +7,7 @@ import { API, getTheme, setToken, getToken } from '@/lib/api';
const AppContext = createContext(null); const AppContext = createContext(null);
function stageSharedGeometry(transition, { name, duration, moveOffset, preserveSizeUntilMove = false }) { function stageSharedGeometry(transition, { name, duration, moveOffset }) {
transition.ready.then(() => { transition.ready.then(() => {
const groupAnimation = document.getAnimations().find( const groupAnimation = document.getAnimations().find(
(animation) => animation.effect?.pseudoElement === `::view-transition-group(${name})` (animation) => animation.effect?.pseudoElement === `::view-transition-group(${name})`
@@ -27,7 +27,7 @@ function stageSharedGeometry(transition, { name, duration, moveOffset, preserveS
}, },
{ {
offset: moveOffset, offset: moveOffset,
width: preserveSizeUntilMove ? start.width : end.width, width: end.width,
height: start.height, height: start.height,
transform: end.transform, transform: end.transform,
easing: 'cubic-bezier(0.4, 0, 0.2, 1)', easing: 'cubic-bezier(0.4, 0, 0.2, 1)',
@@ -238,12 +238,6 @@ export default function AppProvider({ children, cachedName = '' }) {
if (targetTime) targetTime.style.viewTransitionName = 'post-time'; if (targetTime) targetTime.style.viewTransitionName = 'post-time';
}); });
stageSharedGeometry(transition, { name: 'post-expand', duration: 480, moveOffset: 0.72 }); stageSharedGeometry(transition, { name: 'post-expand', duration: 480, moveOffset: 0.72 });
stageSharedGeometry(transition, {
name: 'post-heading',
duration: 480,
moveOffset: 0.72,
preserveSizeUntilMove: true,
});
const clearTargetNames = () => { const clearTargetNames = () => {
if (targetCard) targetCard.style.viewTransitionName = ''; if (targetCard) targetCard.style.viewTransitionName = '';
if (targetTitle) targetTitle.style.viewTransitionName = ''; if (targetTitle) targetTitle.style.viewTransitionName = '';
@@ -284,12 +278,6 @@ export default function AppProvider({ children, cachedName = '' }) {
flushSync(commitNavigation); flushSync(commitNavigation);
}); });
stageSharedGeometry(transition, { name: 'post-expand', duration: 960, moveOffset: 0.62 }); stageSharedGeometry(transition, { name: 'post-expand', duration: 960, moveOffset: 0.62 });
stageSharedGeometry(transition, {
name: 'post-heading',
duration: 960,
moveOffset: 0.62,
preserveSizeUntilMove: true,
});
const clearSourceNames = () => { const clearSourceNames = () => {
sourceElement.style.viewTransitionName = ''; sourceElement.style.viewTransitionName = '';
if (sourceTitle) sourceTitle.style.viewTransitionName = ''; if (sourceTitle) sourceTitle.style.viewTransitionName = '';