精修 WebUI 第十轮:交互终章
- header 滚动时加 isScrolled 类:阴影提一档显得"浮起",区分内容区 - 键盘快捷键:⌘S/Ctrl+S 保存配置,⌘Enter/Ctrl+Enter 启动运行;尊重按钮 disabled 状态 - 通用 tooltip 系统:[data-tooltip] + 可选 data-tooltip-pos="bottom",带小箭头与毛玻璃;移动端禁用避免触摸浮悬 - btnTheme / btnShotFullscreen / 复制按钮 全部接入 tooltip - cache-bust v12 → v13
This commit is contained in:
1 parent
0a2d67afb4
commit
8b8e3129e5
3 files changed
+131
-4
No files matched your search
@@ -459,6 +459,8 @@ function attachCopyButtons() {
|
||||
btn.type = "button";
|
||||
btn.className = "copyBtn";
|
||||
btn.setAttribute("aria-label", "复制");
|
||||
btn.setAttribute("data-tooltip", "复制");
|
||||
btn.setAttribute("data-tooltip-pos", "bottom");
|
||||
btn.innerHTML = '<svg viewBox="0 0 24 24" width="12" height="12" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>';
|
||||
btn.addEventListener("click", async (e) => {
|
||||
e.stopPropagation();
|
||||
@@ -487,6 +489,39 @@ function attachCopyButtons() {
|
||||
}
|
||||
}
|
||||
|
||||
function initKeyboardShortcuts() {
|
||||
const isMac = /Mac|iPhone|iPad|iPod/i.test(navigator.platform || navigator.userAgent || "");
|
||||
document.addEventListener("keydown", (e) => {
|
||||
const mod = isMac ? e.metaKey : e.ctrlKey;
|
||||
if (!mod) return;
|
||||
const key = e.key.toLowerCase();
|
||||
// ⌘S / Ctrl+S → 保存配置
|
||||
if (key === "s") {
|
||||
e.preventDefault();
|
||||
const btn = document.getElementById("btnSave");
|
||||
if (btn && !btn.disabled) btn.click();
|
||||
return;
|
||||
}
|
||||
// ⌘Enter / Ctrl+Enter → 启动运行
|
||||
if (key === "enter") {
|
||||
e.preventDefault();
|
||||
const btn = document.getElementById("btnStart");
|
||||
if (btn && !btn.disabled) btn.click();
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function initHeaderScroll() {
|
||||
const header = document.querySelector(".header");
|
||||
if (!header) return;
|
||||
const onScroll = () => {
|
||||
header.classList.toggle("isScrolled", window.scrollY > 8);
|
||||
};
|
||||
window.addEventListener("scroll", onScroll, { passive: true });
|
||||
onScroll();
|
||||
}
|
||||
|
||||
function initShotFullscreen() {
|
||||
const btn = document.getElementById("btnShotFullscreen");
|
||||
const img = document.getElementById("liveShot");
|
||||
@@ -2006,6 +2041,8 @@ window.addEventListener("DOMContentLoaded", async () => {
|
||||
initFooter();
|
||||
attachCopyButtons();
|
||||
initShotFullscreen();
|
||||
initHeaderScroll();
|
||||
initKeyboardShortcuts();
|
||||
// 首屏统计数字加骨架,待第一次 pollStats 成功后移除
|
||||
document.querySelectorAll(".stat .statValue").forEach((el) => {
|
||||
if ((el.textContent || "").trim() === "-") el.classList.add("skeleton");
|
||||
|
||||
+4
-4
@@ -15,7 +15,7 @@
|
||||
} catch (e) {}
|
||||
})();
|
||||
</script>
|
||||
<link rel="stylesheet" href="styles.css?v=console-20260520-theme-v12" />
|
||||
<link rel="stylesheet" href="styles.css?v=console-20260520-theme-v13" />
|
||||
</head>
|
||||
<body>
|
||||
<div class="app">
|
||||
@@ -86,7 +86,7 @@
|
||||
</span>
|
||||
保存配置
|
||||
</button>
|
||||
<button id="btnTheme" class="btn btnGhost btnIconOnly" type="button" aria-label="切换主题" title="切换主题">
|
||||
<button id="btnTheme" class="btn btnGhost btnIconOnly" type="button" aria-label="切换主题" data-tooltip="切换主题" data-tooltip-pos="bottom">
|
||||
<span class="btnIcon themeIconSun" aria-hidden="true">
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="4"/><path d="M12 2v2"/><path d="M12 20v2"/><path d="m4.93 4.93 1.41 1.41"/><path d="m17.66 17.66 1.41 1.41"/><path d="M2 12h2"/><path d="M20 12h2"/><path d="m6.34 17.66-1.41 1.41"/><path d="m19.07 4.93-1.41 1.41"/></svg>
|
||||
</span>
|
||||
@@ -1156,7 +1156,7 @@
|
||||
<div class="preview">
|
||||
<img id="liveShot" alt="实时截图预览" src="/pic/screenshot.png" />
|
||||
<span id="liveShotTs" class="previewTs" hidden></span>
|
||||
<button id="btnShotFullscreen" type="button" class="previewFullscreen" aria-label="全屏查看">
|
||||
<button id="btnShotFullscreen" type="button" class="previewFullscreen" aria-label="全屏查看" data-tooltip="全屏查看" data-tooltip-pos="bottom">
|
||||
<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 8V3h5"/><path d="M21 8V3h-5"/><path d="M3 16v5h5"/><path d="M21 16v5h-5"/></svg>
|
||||
</button>
|
||||
</div>
|
||||
@@ -1249,6 +1249,6 @@
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
<script src="app.js?v=console-20260520-theme-v12"></script>
|
||||
<script src="app.js?v=console-20260520-theme-v13"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -231,6 +231,15 @@ svg {
|
||||
box-shadow: var(--shadow);
|
||||
backdrop-filter: blur(14px) saturate(1.1);
|
||||
animation: surfaceIn var(--motion-slow) both;
|
||||
transition: box-shadow var(--motion), border-color var(--motion);
|
||||
}
|
||||
|
||||
.header.isScrolled {
|
||||
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.08), 0 1px 0 var(--border) inset;
|
||||
}
|
||||
|
||||
:root[data-theme="dark"] .header.isScrolled {
|
||||
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.55), 0 1px 0 rgba(255, 255, 255, 0.04) inset;
|
||||
}
|
||||
|
||||
.header::before {
|
||||
@@ -2160,6 +2169,87 @@ details[open] > summary.sectionTitle::before {
|
||||
}
|
||||
}
|
||||
|
||||
/* ==================== Tooltip (data-tooltip) ==================== */
|
||||
[data-tooltip] {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
[data-tooltip]::before,
|
||||
[data-tooltip]::after {
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
bottom: calc(100% + 8px);
|
||||
transform: translateX(-50%) translateY(2px);
|
||||
pointer-events: none;
|
||||
opacity: 0;
|
||||
transition: opacity 120ms ease, transform 120ms ease;
|
||||
z-index: 50;
|
||||
}
|
||||
|
||||
[data-tooltip]::before {
|
||||
content: attr(data-tooltip);
|
||||
padding: 5px 8px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius-sm);
|
||||
background: var(--surface);
|
||||
color: var(--text);
|
||||
font-size: var(--text-xs);
|
||||
font-weight: 500;
|
||||
letter-spacing: 0;
|
||||
text-transform: none;
|
||||
white-space: nowrap;
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
|
||||
backdrop-filter: blur(8px);
|
||||
}
|
||||
|
||||
:root[data-theme="dark"] [data-tooltip]::before {
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
|
||||
[data-tooltip]::after {
|
||||
content: "";
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
bottom: calc(100% + 4px);
|
||||
border: 1px solid var(--border);
|
||||
border-top: 0;
|
||||
border-left: 0;
|
||||
background: var(--surface);
|
||||
transform: translateX(-50%) rotate(45deg);
|
||||
}
|
||||
|
||||
[data-tooltip]:hover::before,
|
||||
[data-tooltip]:hover::after,
|
||||
[data-tooltip]:focus-visible::before,
|
||||
[data-tooltip]:focus-visible::after {
|
||||
opacity: 1;
|
||||
transform: translateX(-50%) translateY(0);
|
||||
}
|
||||
|
||||
[data-tooltip]:hover::after,
|
||||
[data-tooltip]:focus-visible::after {
|
||||
transform: translateX(-50%) rotate(45deg);
|
||||
}
|
||||
|
||||
/* Position bottom (below the trigger) */
|
||||
[data-tooltip][data-tooltip-pos="bottom"]::before,
|
||||
[data-tooltip][data-tooltip-pos="bottom"]::after {
|
||||
bottom: auto;
|
||||
top: calc(100% + 8px);
|
||||
}
|
||||
|
||||
[data-tooltip][data-tooltip-pos="bottom"]::after {
|
||||
top: calc(100% + 4px);
|
||||
border: 1px solid var(--border);
|
||||
border-bottom: 0;
|
||||
border-right: 0;
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
[data-tooltip]::before,
|
||||
[data-tooltip]::after { display: none; }
|
||||
}
|
||||
|
||||
/* Global thin scrollbars */
|
||||
* {
|
||||
scrollbar-width: thin;
|
||||
|
||||
Reference in new issue
Block a user