Reduce navigation flash with instant theme background and view transitions.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-26 03:26:57 +08:00
parent aaf69329cb
commit cababd67f5
5 changed files with 51 additions and 5 deletions
+20 -1
View File
@@ -41,10 +41,29 @@
backdrop.addEventListener('click', closeNav);
}
nav.querySelectorAll('a').forEach(function (link) {
function prefetchNav(href) {
if (!href || href.indexOf(window.location.origin) !== 0) return;
if (href === window.location.href) return;
var links = document.head.querySelectorAll('link[rel="prefetch"]');
for (var i = 0; i < links.length; i++) {
if (links[i].href === href) return;
}
var link = document.createElement('link');
link.rel = 'prefetch';
link.href = href;
document.head.appendChild(link);
}
nav.querySelectorAll('a[href]').forEach(function (link) {
link.addEventListener('click', function () {
if (isMobileNav()) closeNav();
});
link.addEventListener('mouseenter', function () {
prefetchNav(link.href);
});
link.addEventListener('touchstart', function () {
prefetchNav(link.href);
}, { passive: true });
});
window.addEventListener('resize', function () {