Spaces:
Running
Running
File size: 1,537 Bytes
445de93 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | const burbuja = document.createElement('div');
burbuja.id = 'tooltip-global';
document.body.appendChild(burbuja);
const MARGEN = 8;
const posicionar = (el) => {
const rect = el.getBoundingClientRect();
const enFooter = el.closest('.nav-inferior') !== null;
burbuja.style.left = '';
burbuja.style.right = '';
let top, left;
if (enFooter) {
top = rect.top - burbuja.offsetHeight - MARGEN;
} else {
top = rect.bottom + MARGEN;
}
left = rect.left + rect.width / 2 - burbuja.offsetWidth / 2;
const margenLateral = 6;
if (left < margenLateral) left = margenLateral;
if (left + burbuja.offsetWidth > window.innerWidth - margenLateral) {
left = window.innerWidth - burbuja.offsetWidth - margenLateral;
}
burbuja.style.top = `${top + window.scrollY}px`;
burbuja.style.left = `${left}px`;
};
let temporizador;
document.addEventListener('mouseover', (e) => {
const el = e.target.closest('[data-tooltip]');
if (!el) return;
clearTimeout(temporizador);
temporizador = setTimeout(() => {
burbuja.textContent = el.dataset.tooltip;
burbuja.classList.add('visible');
posicionar(el);
}, 400);
});
document.addEventListener('mouseout', (e) => {
const el = e.target.closest('[data-tooltip]');
if (!el) return;
clearTimeout(temporizador);
burbuja.classList.remove('visible');
});
document.addEventListener('click', () => {
clearTimeout(temporizador);
burbuja.classList.remove('visible');
});
|