mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-03-10 14:42:33 +01:00
Improve .protyle-scroll tooltip (#12700)
* Update tooltip.ts * Update tooltip.ts * Update index.ts
This commit is contained in:
parent
d2c1603647
commit
61e07a1ed1
2 changed files with 14 additions and 3 deletions
|
|
@ -26,16 +26,23 @@ export const showTooltip = (message: string, target: Element, error = false) =>
|
|||
} else {
|
||||
messageElement.classList.remove("tooltip--memo");
|
||||
}
|
||||
|
||||
let left = targetRect.left;
|
||||
let top = targetRect.bottom;
|
||||
const position = target.getAttribute("data-position");
|
||||
const parentRect = target.parentElement.getBoundingClientRect();
|
||||
|
||||
if (position?.startsWith("right")) {
|
||||
// block icon and background icon
|
||||
left = targetRect.right - messageElement.clientWidth;
|
||||
} else if (position?.startsWith("left")) {
|
||||
left = targetRect.left;
|
||||
}
|
||||
|
||||
if (position?.endsWith("bottom")) {
|
||||
top += parseInt(position.replace("right", ""));
|
||||
top += parseInt(position.replace("right", "").replace("left", ""));
|
||||
} else if (position?.endsWith("top")) {
|
||||
top = targetRect.top - messageElement.clientHeight;
|
||||
} else if (position === "parentE") {
|
||||
// file tree and outline、backlink
|
||||
top = parentRect.top;
|
||||
|
|
@ -45,14 +52,18 @@ export const showTooltip = (message: string, target: Element, error = false) =>
|
|||
top = parentRect.top + 8;
|
||||
left = parentRect.left - messageElement.clientWidth;
|
||||
}
|
||||
|
||||
const topHeight = position === "parentE" ? top : targetRect.top;
|
||||
const bottomHeight = window.innerHeight - top;
|
||||
|
||||
messageElement.style.maxHeight = Math.max(topHeight, bottomHeight) + "px";
|
||||
|
||||
if (top + messageElement.clientHeight > window.innerHeight && topHeight > bottomHeight) {
|
||||
messageElement.style.top = ((position === "parentE" ? parentRect.bottom : targetRect.top) - messageElement.clientHeight) + "px";
|
||||
} else {
|
||||
messageElement.style.top = top + "px";
|
||||
}
|
||||
|
||||
if (left + messageElement.clientWidth > window.innerWidth) {
|
||||
if (position === "parentE") {
|
||||
messageElement.style.left = (parentRect.left - 8 - messageElement.clientWidth) + "px";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue