- 新增收藏功能:favorite 服务与 handler、FavoriteButton 组件 - 新增关注功能:follow 服务与 handler、FollowButton 组件 - 用户主页适配关注/粉丝与收藏展示 - flash 消息工具、广告与侧边栏组件微调
35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
/**
|
||
* 跳转目标高亮:目标区域先铺主题色浅底(--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<HTMLElement, ReturnType<typeof setTimeout>>();
|
||
|
||
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);
|
||
}
|