Reduce navigation flash with instant theme background and view transitions.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,8 +1,25 @@
|
||||
/* Copyright (c) 2025-2026 马建军. All rights reserved. 专有软件,详见 LICENSE.zh-CN.txt */
|
||||
/* 科技感增强层 — 与 base.html 变量配合 */
|
||||
|
||||
@view-transition {
|
||||
navigation: auto;
|
||||
}
|
||||
|
||||
::view-transition-old(app-main),
|
||||
::view-transition-new(app-main) {
|
||||
animation-duration: .18s;
|
||||
}
|
||||
|
||||
::view-transition-old(app-tech-bg),
|
||||
::view-transition-new(app-tech-bg),
|
||||
::view-transition-old(site-header),
|
||||
::view-transition-new(site-header) {
|
||||
animation: none;
|
||||
}
|
||||
|
||||
.tech-bg{
|
||||
position:fixed;inset:0;z-index:0;pointer-events:none;overflow:hidden;
|
||||
view-transition-name:app-tech-bg;
|
||||
}
|
||||
.tech-grid{
|
||||
position:absolute;inset:0;
|
||||
@@ -59,6 +76,7 @@
|
||||
border-bottom:1px solid var(--border-header);
|
||||
background:transparent;
|
||||
backdrop-filter:none;
|
||||
view-transition-name:site-header;
|
||||
}
|
||||
.site-header::after{
|
||||
content:"";display:block;height:1px;margin-top:-1px;
|
||||
|
||||
+20
-1
@@ -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 () {
|
||||
|
||||
@@ -19,10 +19,14 @@
|
||||
theme = 'dark';
|
||||
}
|
||||
document.documentElement.setAttribute('data-theme', theme);
|
||||
document.documentElement.style.colorScheme = theme;
|
||||
document.documentElement.style.background = theme === 'light' ? '#e8eef8' : '#050508';
|
||||
try {
|
||||
localStorage.setItem(KEY, theme);
|
||||
} catch (e) { /* ignore */ }
|
||||
updateButtons(theme);
|
||||
var meta = document.getElementById('meta-theme-color');
|
||||
if (meta) meta.setAttribute('content', theme === 'light' ? '#e8eef8' : '#050508');
|
||||
}
|
||||
|
||||
var saved = null;
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
* 专有软件 — 未经授权禁止复制、传播、转售。
|
||||
* 详见 LICENSE.zh-CN.txt
|
||||
*/
|
||||
var CACHE_VERSION = 'qihuo-v3';
|
||||
var CACHE_VERSION = 'qihuo-v4';
|
||||
var STATIC_CACHE = CACHE_VERSION + '-static';
|
||||
var STATIC_ASSETS = [
|
||||
'/static/css/tech.css',
|
||||
|
||||
Reference in New Issue
Block a user