added view transition

This commit is contained in:
sairaj mote 2023-09-20 13:47:41 +05:30
parent abe29d489f
commit 0a6408cb53
4 changed files with 108 additions and 8 deletions

View File

@ -1133,4 +1133,64 @@ h3 {
}
.hidden {
display: none !important;
}
::view-transition-old(root) {
-webkit-animation: slide-up-out 0.3s both;
animation: slide-up-out 0.3s both;
}
::view-transition-new(root) {
-webkit-animation: slide-up-in-place 0.3s both;
animation: slide-up-in-place 0.3s both;
}
@-webkit-keyframes slide-up-in-place {
from {
opacity: 0;
transform: translateY(1rem);
}
to {
opacity: 1;
transform: translateY(0);
}
}
@keyframes slide-up-in-place {
from {
opacity: 0;
transform: translateY(1rem);
}
to {
opacity: 1;
transform: translateY(0);
}
}
@-webkit-keyframes slide-up-out {
from {
opacity: 1;
transform: translateY(0);
}
to {
opacity: 0;
transform: translateY(-1rem);
}
}
@keyframes slide-up-out {
from {
opacity: 1;
transform: translateY(0);
}
to {
opacity: 0;
transform: translateY(-1rem);
}
}
@media (prefers-reduced-motion) {
::view-transition-group(*),
::view-transition-old(*),
::view-transition-new(*) {
-webkit-animation: none !important;
animation: none !important;
}
}

2
css/main.min.css vendored

File diff suppressed because one or more lines are too long

View File

@ -1098,3 +1098,37 @@ h3 {
.hidden {
display: none !important;
}
::view-transition-old(root) {
animation: slide-up-out 0.3s both;
}
::view-transition-new(root) {
animation: slide-up-in-place 0.3s both;
}
@keyframes slide-up-in-place {
from {
opacity: 0;
transform: translateY(1rem);
}
to {
opacity: 1;
transform: translateY(0);
}
}
@keyframes slide-up-out {
from {
opacity: 1;
transform: translateY(0);
}
to {
opacity: 0;
transform: translateY(-1rem);
}
}
@media (prefers-reduced-motion) {
::view-transition-group(*),
::view-transition-old(*),
::view-transition-new(*) {
animation: none !important;
}
}

View File

@ -268,8 +268,18 @@
this.routingStart(this.state)
}
if (this.routes[page]) {
await this.routes[page](this.state)
this.lastPage = page
// Fallback for browsers that don't support View transition API:
if (!document.startViewTransition) {
await this.routes[page](this.state)
this.lastPage = page
return;
}
// With a transition:
document.startViewTransition(async () => {
await this.routes[page](this.state)
this.lastPage = page
});
} else {
if (this.routes['404']) {
this.routes['404'](this.state);
@ -1312,11 +1322,7 @@
// routing logic
const router = new Router({
routingStart(state) {
const { page } = state
if ("scrollRestoration" in history) {
history.scrollRestoration = "manual";
}
window.scrollTo(0, 0);
const { page } = state;
if (floGlobals.myFloID && !getRef('main_header')) {
renderElem(getRef('app_body'), html`
<header id="main_header">