mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
ui: add view-transistions
This commit is contained in:
6 files changed
+49
-24
No files matched your search
@@ -183,6 +183,23 @@ export const request = {
|
||||
},
|
||||
};
|
||||
|
||||
export function withTransistionCallback(callback: () => (Promise<void> | void)) {
|
||||
// @ts-ignore
|
||||
if (!document.startViewTransition) return callback?.();
|
||||
// @ts-ignore
|
||||
return document.startViewTransition(() => callback());
|
||||
}
|
||||
|
||||
export async function setTemporaryViewTransitionNames(entries, vtPromise: Promise<void>) {
|
||||
for (const [$el, name] of entries) {
|
||||
$el.style.viewTransitionName = name;
|
||||
}
|
||||
await vtPromise;
|
||||
for (const [$el] of entries) {
|
||||
$el.style.viewTransitionName = '';
|
||||
}
|
||||
}
|
||||
|
||||
Object.assign(window.Hydro.utils, {
|
||||
i18n,
|
||||
rawHtml,
|
||||
@@ -192,4 +209,6 @@ Object.assign(window.Hydro.utils, {
|
||||
tpl,
|
||||
delay,
|
||||
zIndexManager,
|
||||
withTransistionCallback,
|
||||
setTemporaryViewTransitionNames,
|
||||
});
|
||||
@@ -5,7 +5,7 @@ import $ from 'jquery';
|
||||
import { nanoid } from 'nanoid';
|
||||
import NProgress from 'nprogress';
|
||||
import Notification from 'vj/components/notification';
|
||||
import { request } from './base';
|
||||
import { request, withTransistionCallback } from './base';
|
||||
|
||||
const pjax = {};
|
||||
|
||||
@@ -115,7 +115,7 @@ pjax.request = async (opt) => {
|
||||
}
|
||||
}
|
||||
$target.trigger('vjContentRemove');
|
||||
$target.replaceWith($el);
|
||||
withTransistionCallback(() => $target.replaceWith($el));
|
||||
$el.trigger('vjContentNew');
|
||||
}
|
||||
} catch (err) {
|
||||
|
||||
Reference in new issue
Block a user