This commit is contained in:
2023-06-05 10:09:25 +08:00
parent a930a2bf5b
commit 93d5be462e
5 changed files with 111 additions and 65 deletions

View File

@ -66,15 +66,33 @@ function setTooltip(container, content, flag = false, parent = null) {
}
}
p = c.parentElement;
const offsetParent = c.offsetParent;
while (p != null && p !== (isParent ? parent : offsetParent)) {
const offsetParent = isParent ? parent : c.offsetParent;
while (p != null && p !== offsetParent) {
left -= p.scrollLeft;
top -= p.scrollTop;
p = p.parentElement;
}
left += (c.offsetWidth - wrapper.offsetWidth) / 2;
top -= wrapper.offsetHeight + 14;
wrapper.style.left = `${left}px`;
// check overflow
let t = c.offsetTop;
p = c.offsetParent;
while (p != null) {
const overflow = window.getComputedStyle(p).overflow;
if (overflow !== 'visible') {
break;
}
t += p.offsetTop;
p = p.offsetParent;
}
const offsetHeight = wrapper.offsetHeight + 14;
if (t + top - offsetHeight < 0) {
top += c.parentElement.offsetHeight + 14;
wrapper.classList.add('ui-tooltip-down');
} else {
top -= offsetHeight;
wrapper.classList.remove('ui-tooltip-down');
}
wrapper.style.top = `${top}px`;
wrapper.style.visibility = 'visible';
wrapper.style.opacity = 1;