精修 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");
|
||||
|
||||
Reference in new issue
Block a user