PageRevealEvent
Ограниченная доступность
Эта функция не относится к Baseline, так как не работает в некоторых из самых широко используемых браузеров.
Объект события PageRevealEvent доступен внутри обработчиков события pagereveal.
Во время перехода между документами, он позволяет манипулировать связанным переходом просмотра (предоставляя доступ к соответствующему объекту ViewTransition) в документе, к которому происходит переход, если переход просмотра был вызван этим переходом.
Вне переходов просмотра, это событие также полезно для таких случаев, как запуск анимации запуска или отчёт о просмотре страницы. Оно эквивалентно первому выполнению Window.requestAnimationFrame() после перехода между документами, если вы вызовете requestAnimationFrame() в <head> документа. Например, если вы выполните следующую reveal() функцию в <head>:
function reveal() {
// Include startup animation here
}
/* This will fire in the first rendered frame after loading */
requestAnimationFrame(() => reveal());
/* This will fire if the page is restored from BFCache */
window.onpagehide = () => requestAnimationFrame(() => reveal());
Конструктор
PageRevealEvent()-
Создаёт новый экземпляр объекта
PageRevealEvent.
Свойства экземпляра
-
viewTransitionТолько для чтения -
Содержит объект
ViewTransition, представляющий активный переход просмотра для перехода между документами.
Примеры
window.addEventListener("pagereveal", async (e) => {
// If the "from" history entry does not exist, return
if (!navigation.activation.from) return;
// Only run this if an active view transition exists
if (e.viewTransition) {
const fromUrl = new URL(navigation.activation.from.url);
const currentUrl = new URL(navigation.activation.entry.url);
// Went from profile page to homepage
// ~> Set VT names on the relevant list item
if (isProfilePage(fromUrl) && isHomePage(currentUrl)) {
const profile = extractProfileNameFromUrl(fromUrl);
// Set view-transition-name values on the elements to animate
document.querySelector(`#${profile} span`).style.viewTransitionName =
"name";
document.querySelector(`#${profile} img`).style.viewTransitionName =
"avatar";
// Remove names after snapshots have been taken
// so that we're ready for the next navigation
await e.viewTransition.ready;
document.querySelector(`#${profile} span`).style.viewTransitionName =
"none";
document.querySelector(`#${profile} img`).style.viewTransitionName =
"none";
}
// Went to profile page
// ~> Set VT names on the main title and image
if (isProfilePage(currentUrl)) {
// Set view-transition-name values on the elements to animate
document.querySelector(`#detail main h1`).style.viewTransitionName =
"name";
document.querySelector(`#detail main img`).style.viewTransitionName =
"avatar";
// Remove names after snapshots have been taken
// so that we're ready for the next navigation
await e.viewTransition.ready;
document.querySelector(`#detail main h1`).style.viewTransitionName =
"none";
document.querySelector(`#detail main img`).style.viewTransitionName =
"none";
}
}
});
Примечание: См. Список разработчиков Chrome DevRel для демонстрации, взятой из этого кода.
Спецификации
| Спецификация |
|---|
| HTML # the-pagerevealevent-interface |
Совместимость браузеров
| Рабочий стол | Мобильный | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox для Android | Opera Android | Safari на IOS | Samsung Internet | WebView Android | |
PageRevealEvent |
128 | 128 | Нет | 114 | 18.2 | 128 | Нет | 85 | 18.2 | Нет | 128 |
PageRevealEvent |
123 | 123 | Нет | 109 | 18.2 | 123 | Нет | 82 | 18.2 | 27.0 | 123 |
viewTransition |
126 | 126 | Нет | 112 | 18.2 | 126 | Нет | 83 | 18.2 | Нет | 126 |
См. также
© 2005–2024 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/PageRevealEvent