Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function showTooltip(element, islandName, username) {
- try {
- const tooltip = document.getElementById('tooltip');
- const mapContainer = document.querySelector('.map-container');
- const containerRect = mapContainer.getBoundingClientRect();
- const pointLeft = element.offsetLeft;
- const pointTop = element.offsetTop;
- // Tooltip-Inhalt
- tooltip.textContent = `${islandName} (${username})`;
- tooltip.style.display = 'block';
- tooltip.style.position = 'absolute';
- // Tooltip vorübergehend sichtbar machen für Messung
- tooltip.style.visibility = 'hidden';
- tooltip.style.left = '0px';
- tooltip.style.top = '0px';
- // Größe berechnen
- const tooltipWidth = tooltip.offsetWidth;
- const tooltipHeight = tooltip.offsetHeight;
- // Zielposition (oberhalb des Punkts, zentriert)
- let tooltipLeft = pointLeft + element.offsetWidth / 2 - tooltipWidth / 2;
- let tooltipTop = pointTop - tooltipHeight - 10;
- // Randkorrekturen (linker und rechter Rand)
- const padding = 5;
- if (tooltipLeft < padding) {
- tooltipLeft = padding;
- } else if (tooltipLeft + tooltipWidth > mapContainer.offsetWidth - padding) {
- tooltipLeft = mapContainer.offsetWidth - tooltipWidth - padding;
- }
- // Falls Tooltip oberhalb des Containers rausragen würde → darunter anzeigen
- if (tooltipTop < padding) {
- tooltipTop = pointTop + element.offsetHeight + 10;
- }
- // Endgültig setzen
- tooltip.style.left = `${tooltipLeft}px`;
- tooltip.style.top = `${tooltipTop}px`;
- tooltip.style.visibility = 'visible';
- console.log(`Tooltip für ${username} bei x=${tooltipLeft}px, y=${tooltipTop}px`);
- } catch (e) {
- console.error('Error in showTooltip:', e);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment