mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-06 16:58:49 +01:00
This commit is contained in:
parent
827b3a4650
commit
f8b6ce02ab
1 changed files with 10 additions and 4 deletions
|
|
@ -67,15 +67,21 @@ export const scrollCenter = (protyle: IProtyle, nodeElement?: Element, top = fal
|
|||
offsetTop += (parentNodeElement as HTMLElement).offsetTop;
|
||||
parentNodeElement = parentNodeElement.parentElement;
|
||||
}
|
||||
let contentTop = 0;
|
||||
let topElement = protyle.element.firstElementChild
|
||||
while (topElement && !topElement.classList.contains("protyle-content")) {
|
||||
contentTop += topElement.clientHeight
|
||||
topElement = topElement.nextElementSibling;
|
||||
}
|
||||
if (top) {
|
||||
protyle.contentElement.scroll({top: offsetTop - 32, behavior});
|
||||
protyle.contentElement.scroll({top: offsetTop - contentTop, behavior});
|
||||
return;
|
||||
}
|
||||
if (protyle.contentElement.scrollTop > offsetTop - 32) {
|
||||
protyle.contentElement.scroll({top: offsetTop - 32, behavior});
|
||||
} else if (protyle.contentElement.scrollTop + protyle.contentElement.clientHeight < offsetTop + nodeElement.clientHeight - 32) {
|
||||
protyle.contentElement.scroll({top: offsetTop - contentTop, behavior});
|
||||
} else if (protyle.contentElement.scrollTop + protyle.contentElement.clientHeight < offsetTop + nodeElement.clientHeight - contentTop) {
|
||||
protyle.contentElement.scroll({
|
||||
top: offsetTop + nodeElement.clientHeight - 32 - protyle.contentElement.clientHeight,
|
||||
top: offsetTop + nodeElement.clientHeight - contentTop - protyle.contentElement.clientHeight,
|
||||
behavior
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue