This commit is contained in:
2025-12-24 10:55:40 +08:00
parent eec9d6045c
commit 752bb23571
25 changed files with 2348 additions and 816 deletions

View File

@@ -4,7 +4,7 @@ import { global } from '../utility';
const pointerHeight = 12;
export function setTooltip(container, content, flag = false, parent = null) {
export function setTooltip(container, content, flag = false, parent = null, maxLeft = null) {
const isParent = parent instanceof HTMLElement;
if (isParent) {
const tipid = container.dataset.tipId;
@@ -54,6 +54,7 @@ export function setTooltip(container, content, flag = false, parent = null) {
return;
}
if (!flag || c.scrollWidth > c.offsetWidth) {
wrapper.style.cssText += 'left: -9999px; top: -9999px; display: block';
tid = setTimeout(() => {
let p;
let left;
@@ -75,7 +76,6 @@ export function setTooltip(container, content, flag = false, parent = null) {
top -= p.scrollTop;
p = p.parentElement;
}
wrapper.style.display = '';
const offsetHeight = wrapper.offsetHeight;
const offsetWidth = wrapper.offsetWidth;
if (isParent) {
@@ -150,6 +150,15 @@ export function setTooltip(container, content, flag = false, parent = null) {
left = lastWidth - offsetWidth - 1;
}
}
if (typeof maxLeft === 'function') {
const max = maxLeft(offsetWidth);
if (left > max) {
wrapper.style.setProperty('--pointer-left', 'calc(100% - 20px)');
left = max;
} else {
wrapper.style.setProperty('--pointer-left', null);
}
}
// wrapper.style.left = `${left}px`;
// wrapper.style.top = `${top}px`;
// wrapper.style.visibility = 'visible';