jakearchibald/navigation-transitions là dự án mã nguồn mở trên GitHub, với 333 sao.
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
If you want to transition between pages, your current option is to fetch the new page with JavaScript, update the URL with pushState, and animate between the two.
Having to reimplement navigation for a simple transition is a bit much, often leading developers to use large frameworks where they could otherwise be avoided. This proposal provides a low-level way to create transitions while maintaining regular browser navigation.
Goals
Enable complex transitions.
Allow transitions to start while the next page is being fetched.
Allow transitions to differ between navigation from clicking a link, back button, forward button, reload button, etc.
Allow transitions to cater for a non-zero scroll position in the navigated-to page.
Experiments, talks & reading materials
Web Navigation Transitions (2014): CSS-based experiment by Google Chrome team
Spec: Initial (deprecated) spec for experimental Web Navigation Transitions prototype (2014)
Talk (video): Ryan Schoen's talk, Wicked Fast: Performance investments (Chrome Dev Summit 2014)
Demo (video): Web Navigation Transitions in Chrome on Android
Demo (video): Android's Activities Transitions API and experimental Web Navigation Transitions in Chrome on Android
Web Navigation Transitions (2015): CSS-based proposal by Chris Lord (Mozilla, Firefox OS)
Article: Web Navigation Transitions by Chris Lord (Mozilla)
Examples: Web Navigation Transitions examples (emulated with CSS Animations, custom CSS media queries, events, <iframe>s, postMessage, etc.)
Code samples: Source code of "Gaia Navigator" Web Navigation Transitions examples
Web Navigation Transitions (2016): New proposal by Jake Archibald (Google Chrome)
Talk (video): Intro to this proposal (Chrome Dev Summit 2016)
The navigate event fires when the document is being navigated in a way that would replace the current document.
event.type - The name of this event, navigate.
event.reason - The way in which the document is being navigated to. One of the following strings:
back - User is navigating back.
forward - User is navigating forward.
reload - Reload-triggered navigation.
normal - Not one of the above.
event.url - The URL being navigated to. An empty string if the URL is of another origin.
event.newWindow - A promise for a WindowProxy being navigated to. Resolves with undefined if another origin is involved in the navigation (i.e., the initial URL or URLs of redirects). Rejects if the navigation fails. Cancels if the navigation cancels (dependent on cancelable promises).
event.transitionUntil(promise) - Keep this document alive and potentially visible until promise settles, or once another origin is involved in the navigation (i.e., the initial URL or URLs of redirects).
Note: The same-origin restrictions are to avoid new URL leaks and timing attacks.
The above examples don't begin to animate until the new page has fetched and become interactive. That's ok, but this API allows the current page to transition while the new page is being fetched, improving the perception of performance:
window.addEventListener('navigate', event => {
if (event.reason == 'reload') return;
const newURL = new URL(event.url);
if (newURL.origin !== location.origin) return;
const documentRect = document.documentElement.getBoundingClientRect();
// Create something that looks like the shell of the new page
const pageShell = createPageShellFor(event.url);
document.body.appendChild(pageShell);
const directionMultiplier = event.reason == 'back' ? -1 : 1;
pageShell.style.transform = `translate(${100 * directionMultiplier}%, ${-documentRect.top}px)`;
const slideAnim = document.body.animate({
transform: `translate(${100 * directionMultiplier}%, 0)`
}, 500);
event.transitionUntil(
event.newWindow.then(newWin => {
if (!newWin) return;
return slideAnim.finished.then(() => {
return newWin.document.documentElement
.animate({opacity: 0}, 200).finished;
});
})
);
});
Rendering & interactivity
During the transition, the document with the highest z-index on the documentElement will render on top. If z-indexes are equal, the entering document will render on top. Both documentElements will generate stacking contexts.
If the background of html/body is transparent, the underlying document will be visible through it. Beneath both documents is the browser's default background (usually white).
During the transition, the render-box of the documents will be clipped to that of the viewport size. This means html { transform: translate(0, -20px); } on the top document will leave a 20-pixel gap at the bottom, through which the bottom document will be visible. After the transition, rendering switches back to using the regular model.
We must guarantee that the new document doesn't visibly appear until event.newWindow's reactions have completed.
As for interactivity, both documents will be at least scrollable, although developers could prevent this using pointer-events: none or similar.
Apologies for the hand-waving.
Place within the navigation algorithm
It feels like the event should fire immediately after step 10 of navigate. If transitionUntil is called, the browser would consider the pages to be transitioning.
The rest of the handling would likely be in the "update the session history with the new page" algorithm. The unloading of the current document would be delayed but without delaying the loading of the new document.
Yep, more hand-waving.
Potential issues & questions
Can transitions/animations be reliably synchronised between documents? They at least share an event loop.
Any issues with firing transitions/animations for nested contexts?
What if the promise passed to transitionUntil never resolves? Feels like it should have a timeout.
What happens on low-end devices that can't display two documents at once?
What if the navigation is cancelled (e.g., use of a Content-Disposition response header). event.newWindow could also cancel.
How does this interact with browsers that have a back-forward cache?
How should redirects be handled?
How should interactivity during the transition be handled?
During a sliding transitions, is it possible to switch a fake shell for the actual page's document mid-transition? Feels like this is something the Animation API should be able to do.
Đọc thêm về jakearchibald/navigation-transitions ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/jakearchibald/navigation-transitions là nguồn chính thức.
jakearchibald/navigation-transitions có bao nhiêu sao?
jakearchibald/navigation-transitions có 333 sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/jakearchibald/navigation-transitions. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
jakearchibald/navigation-transitions có phải mã nguồn mở không?
TopGit chưa ghi nhận license cho jakearchibald/navigation-transitions. Phần lớn repo public trên GitHub là mã nguồn mở, nhưng điều khoản khác nhau từng repo — mở file LICENSE để xác nhận.
jakearchibald/navigation-transitions có tag gì không?
Bản đồng bộ chưa ghi nhận topic GitHub nào cho jakearchibald/navigation-transitions. GitHub topics hiển thị ở thanh bên phải trang repo — đó là nơi đáng kiểm tra nhất.
jakearchibald/navigation-transitions có website riêng không?
TopGit chưa ghi nhận URL trang chủ cho jakearchibald/navigation-transitions. Phần README ở tab phía trên thường có link demo, hoặc xem mô tả GitHub của repo.
jakearchibald/navigation-transitions còn đang phát triển không?
Commit gần nhất trên jakearchibald/navigation-transitions là 8.9 năm trước (theo timestamp GitHub). Repo có 11 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
Đọc đầy đủ README ở tab phía trên.
Muốn nghe thêm một ý kiến về navigation-transitions?
Hỏi một AI đọc được trang này — một cú bấm là có ngay nhận định về navigation-transitions.