/** * 跳转目标高亮:目标区域先铺主题色浅底(--accent-soft)再渐隐。 * 供评论深链定位与文章目录树跳转共用;样式见 globals.css 的 .j13-flash-target。 */ import { scrollBehavior } from "@/lib/motion"; const FLASH_MS = 1800; const CLEANUP_MS = FLASH_MS + 300; const timers = new WeakMap>(); export function flashElement(el: HTMLElement | null | undefined) { if (!el) return; el.classList.remove("j13-flash-target"); // 强制重排,支持连续触发同一元素 void el.offsetWidth; el.classList.add("j13-flash-target"); const prev = timers.get(el); if (prev) clearTimeout(prev); timers.set( el, setTimeout(() => { el.classList.remove("j13-flash-target"); timers.delete(el); }, CLEANUP_MS) ); } /** 滚动到目标(尊重平滑滚动开关与 scroll-margin)并高亮渐隐 */ export function scrollFlashTo(el: HTMLElement | null | undefined, block: ScrollLogicalPosition = "start") { if (!el) return; el.scrollIntoView({ behavior: scrollBehavior(), block }); flashElement(el); }