-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtooltip.js
More file actions
22 lines (17 loc) · 824 Bytes
/
Copy pathtooltip.js
File metadata and controls
22 lines (17 loc) · 824 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
document.addEventListener('DOMContentLoaded', () => {
const tooltips = document.querySelectorAll('.tooltip');
tooltips.forEach(tooltip => {
tooltip.addEventListener('mouseenter', () => {
const after = window.getComputedStyle(tooltip, '::after');
const rect = tooltip.getBoundingClientRect();
const tooltipWidth = tooltip.offsetWidth;
const afterWidth = Math.min(window.innerWidth * 0.33, 500);
const idealLeft = rect.left + (tooltipWidth / 2) - (afterWidth / 2);
const minLeft = 18;
const maxLeft = window.innerWidth - afterWidth - 18;
const clampedLeft = Math.max(minLeft, Math.min(idealLeft, maxLeft));
const offset = clampedLeft - idealLeft;
tooltip.style.setProperty('--tooltip-offset', `${offset}px`);
});
});
});