UI style adjustment

This commit is contained in:
2023-06-05 15:21:56 +08:00
parent 93d5be462e
commit 2366b378d2
4 changed files with 138 additions and 36 deletions

View File

@ -72,10 +72,10 @@ function setTooltip(container, content, flag = false, parent = null) {
top -= p.scrollTop;
p = p.parentElement;
}
left += (c.offsetWidth - wrapper.offsetWidth) / 2;
wrapper.style.left = `${left}px`;
// check overflow
let t = c.offsetTop;
let l = c.offsetLeft;
let lastWidth = c.offsetWidth;
p = c.offsetParent;
while (p != null) {
const overflow = window.getComputedStyle(p).overflow;
@ -83,16 +83,26 @@ function setTooltip(container, content, flag = false, parent = null) {
break;
}
t += p.offsetTop;
l += p.offsetLeft;
lastWidth = p.offsetWidth;
p = p.offsetParent;
}
const offsetHeight = wrapper.offsetHeight + 14;
if (t + top - offsetHeight < 0) {
top += c.parentElement.offsetHeight + 14;
top += c.parentElement.offsetHeight + 10;
wrapper.classList.add('ui-tooltip-down');
} else {
top -= offsetHeight;
wrapper.classList.remove('ui-tooltip-down');
}
const offsetWidth = wrapper.offsetWidth;
left += (c.offsetWidth - offsetWidth) / 2;
if (left < -l) {
left = 2;
} else if (left + offsetWidth + 2 > lastWidth) {
left = lastWidth - offsetWidth - 2;
}
wrapper.style.left = `${left}px`;
wrapper.style.top = `${top}px`;
wrapper.style.visibility = 'visible';
wrapper.style.opacity = 1;