sync issue fixes, and add more comments.

This commit is contained in:
2024-02-19 17:32:11 +08:00
parent 3fd1b5982a
commit 7770aa10a0
6 changed files with 762 additions and 788 deletions

View File

@ -2,6 +2,8 @@ import './css/tooltip.scss';
import { createElement } from "../functions";
// import { global } from "../utility";
const pointerHeight = 12;
export function setTooltip(container, content, flag = false, parent = null) {
const isParent = parent instanceof HTMLElement;
if (isParent) {
@ -77,9 +79,9 @@ export function setTooltip(container, content, flag = false, parent = null) {
const offsetHeight = wrapper.offsetHeight;
const offsetWidth = wrapper.offsetWidth;
if (isParent) {
top -= offsetHeight + 14;
if (top < -offsetHeight) {
top += c.offsetHeight + offsetHeight + 14;
top -= offsetHeight + pointerHeight;
if (top < 0) {
top += c.offsetHeight + offsetHeight + pointerHeight * 2;
wrapper.classList.add('ui-tooltip-down');
}
left += (c.offsetWidth - offsetWidth) / 2;
@ -125,20 +127,20 @@ export function setTooltip(container, content, flag = false, parent = null) {
p = p.parentElement;
}
}
if (t - offsetHeight - 14 < 0) {
if (t - offsetHeight - pointerHeight < 0) {
const containerOffsetHeight = c.offsetHeight;
if (t + containerOffsetHeight + offsetHeight + 14 > lastHeight) {
if (t + containerOffsetHeight + offsetHeight + pointerHeight > lastHeight) {
top = t + (containerOffsetHeight - offsetHeight) / 2;
if (top + offsetHeight + 1 > lastHeight) {
top = lastHeight - offsetHeight - 1;
}
wrapper.classList.add('ui-tooltip-no');
} else {
top += containerOffsetHeight + 14;
top += containerOffsetHeight + pointerHeight;
wrapper.classList.add('ui-tooltip-down');
}
} else {
top -= offsetHeight + 14;
top -= offsetHeight + pointerHeight;
wrapper.classList.remove('ui-tooltip-down');
}
left += (c.offsetWidth - offsetWidth) / 2;