改进悬浮提示元素位置计算
messageElement.innerHTML = message; 会更新元素的内容,元素此时的 left 属性会对元素的宽度产生影响,导致更新后的元素(比如元素内的文本意外换行了)与直接新建的元素(元素内的文本不会换行)宽度不一致。messageElement.clientWidth 会获取到不符合预期的宽度,进而导致 left 计算错误。
This commit is contained in:
parent
76bc95475f
commit
77280e9fbe
1 changed files with 4 additions and 0 deletions
|
@ -61,6 +61,10 @@ export const showTooltip = (message: string, target: Element, tooltipClass?: str
|
|||
|
||||
messageElement.style.maxHeight = Math.max(topHeight, bottomHeight) + "px";
|
||||
|
||||
// 避免原本的 top 和 left 影响计算
|
||||
messageElement.style.top = "0px";
|
||||
messageElement.style.left = "0px";
|
||||
|
||||
if (top + messageElement.clientHeight > window.innerHeight && topHeight > bottomHeight) {
|
||||
messageElement.style.top = ((position === "parentE" ? parentRect.bottom : targetRect.top) - messageElement.clientHeight) + "px";
|
||||
} else {
|
||||
|
|
Loading…
Add table
Reference in a new issue