const OFFSET = 12; export class Tooltip { private timeout: number | null = null; constructor(private element: HTMLElement) { document.body.addEventListener("mousemove", (event: MouseEvent) => { this.element.style.opacity = "1"; this.element.style.left = event.x + OFFSET + "px"; this.element.style.top = event.y + OFFSET + "px"; if (this.timeout) clearTimeout(this.timeout); this.timeout = setTimeout(() => { this.element.style.opacity = "0.8"; }, 1000); }); } setText(text: string) { this.element.style.display = text ? "block" : "none"; this.element.innerHTML = text; } }