diff options
| author | eltrac <hi@eltr.ac> | 2026-04-07 14:53:17 +0800 |
|---|---|---|
| committer | eltrac <hi@eltr.ac> | 2026-04-07 14:53:17 +0800 |
| commit | 10431bd8f5ff71690ae4e5444e8d7894fd401ae5 (patch) | |
| tree | 62b7fd1b6c1f68d2804f380eb522bcebeb2c8d9f /assets/js/tooltip.js | |
| parent | 3e0edacc4a0cafa53ede57ebb6f0378c93f3123b (diff) | |
chore: move templates out of site repo
Diffstat (limited to 'assets/js/tooltip.js')
| -rw-r--r-- | assets/js/tooltip.js | 54 |
1 files changed, 0 insertions, 54 deletions
diff --git a/assets/js/tooltip.js b/assets/js/tooltip.js deleted file mode 100644 index eea5b350..00000000 --- a/assets/js/tooltip.js +++ /dev/null @@ -1,54 +0,0 @@ -(() => { - const allTooltipped = document.querySelectorAll('[data-tooltip]'); - - const createOrUpdateTooltip = (element) => { - const tooltipText = element.getAttribute('data-tooltip') || element.getAttribute('title'); - - if (!tooltipText) return; - - let tooltipElement = element.querySelector('.__generated-tooltip'); - if (!tooltipElement) { - element.classList.add('group', 'relative', 'tooltipped'); - - tooltipElement = document.createElement('div'); - tooltipElement.classList.add( - '__generated-tooltip', - ...'absolute bottom-full left-1/2 transform -translate-x-1/2 translate-y-1 bg-black/80 text-white px-2.5 py-1.5 rounded text-xs whitespace-nowrap opacity-0 invisible transition-all duration-300 pointer-events-none mb-2 z-1000 group-hover:opacity-100 group-hover:visible group-hover:translate-y-0 dark:bg-white/90 dark:text-black'.split(' ') - ); - element.appendChild(tooltipElement); - } - - tooltipElement.textContent = tooltipText; - }; - - const observer = new IntersectionObserver((entries, obs) => { - entries.forEach(entry => { - if (!entry.isIntersecting) return; - - const element = entry.target; - createOrUpdateTooltip(element); - - // listen to tooltip text changes - const mutationObserver = new MutationObserver(mutations => { - for (const mutation of mutations) { - if (mutation.type === 'attributes' && - (mutation.attributeName === 'title' || mutation.attributeName === 'data-tooltip')) { - createOrUpdateTooltip(element); - } - } - }); - - mutationObserver.observe(element, { - attributes: true, - attributeFilter: ['title', 'data-tooltip'], - }); - - obs.unobserve(element); // 不再需要 Intersection 监听 - }); - }, { - rootMargin: '100px', - threshold: 0.1, - }); - - allTooltipped.forEach(el => observer.observe(el)); -})(); |
