[CSS] View Transition
/* View Transitions */
/* STEP 1 */
::view-transition-old(root),
::view-transition-new(root) {
animation-duration: 1s;
}
/* STEP 2 */
@keyframes fade-in {
from { opacity: 0; }
}
@keyframes fade-out {
to { opacity: 0; }
}
@keyframes slide-from-right {
from { transform: translateX(60px); }
}
@keyframes slide-to-left {
to { transform: translateX(-60px); }
}
::view-transition-old(root) {
animation: 90ms cubic-bezier(0.4, 0, 1, 1) both fade-out,
300ms cubic-bezier(0.4, 0, 0.2, 1) both slide-to-left;
}
::view-transition-new(root) {
animation: 210ms cubic-bezier(0, 0, 0.2, 1) 90ms both fade-in,
300ms cubic-bezier(0.4, 0, 0.2, 1) both slide-from-right;
}
/* STEP 3 */
body>header {
// this allow header escape root view transition
view-transition-name: main-header;
}
/* STEP 4 */
details-page::part(image) {
width: 120%;
margin-left: -10%;
}
::view-transition-new(image) {
animation: 210ms cubic-bezier(0, 0, 0.2, 1) 90ms both fade-in
}
Let's say we have a ProductList page and DetailPage... and we will display same image in both page, we want to apply view transition on the image.
ProducList page:
// add view transition control
// the viewTransitionName for product list page should match the viewTransitionName for product detail page
this.querySelector("img").style.viewTransitionName = `image-${product.id}`;
Detail Page:
this.root.querySelector(
"img"
).style.viewTransitionName = `image-${this.product.id}`;
Code: https://github.com/zhentian-wan/webapp-patterns-projects/blob/main/CoffeeMasters/final/styles.css
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
2021-08-20 [Supabase] Use Triggers to Automatically Update Your Supabase Tables
2021-08-20 [SAA + SAP] 31. Migrations
2020-08-20 [React] Using react-styleguidist for Component demo
2019-08-20 [GraphQL] Query Lists of Multiple Types using a Union in GraphQL
2019-08-20 [GraphQL] Query GraphQL Interface Types in GraphQL Playground
2019-08-20 [GraphQL] Reuse GraphQL Selection Sets with Fragments
2019-08-20 [GraphQL] Use an Input Type to Create an Account with a GraphQL Mutation