1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-06 17:33:18 +00:00

repair refresh page scroll bug

This commit is contained in:
shanshuirenjia
2022-05-27 14:08:38 +08:00
parent 8bc72defa5
commit c78dfd7c09

View File

@@ -70,6 +70,15 @@ class WikiMarkdownViewer extends React.Component {
this.titlesInfo = markdownViewer.titlesInfo; this.titlesInfo = markdownViewer.titlesInfo;
} }
getTitlesInfo = () => {
let titlesInfo = [];
let headingList = document.querySelectorAll('h2[id^="user-content"], h3[id^="user-content"]');
for (let i = 0; i < headingList.length; i++) {
titlesInfo.push(headingList[i].offsetTop);
}
this.titlesInfo = titlesInfo;
}
onLinkClick = (event) => { onLinkClick = (event) => {
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
@@ -89,6 +98,10 @@ class WikiMarkdownViewer extends React.Component {
onScrollHandler = () => { onScrollHandler = () => {
const contentScrollTop = this.markdownContainer.current.scrollTop + 180; const contentScrollTop = this.markdownContainer.current.scrollTop + 180;
let titlesLength = this.titlesInfo.length; let titlesLength = this.titlesInfo.length;
if (titlesLength === 0) {
this.getTitlesInfo();
titlesLength = this.titlesInfo.length;
}
let activeTitleIndex; let activeTitleIndex;
if (contentScrollTop <= this.titlesInfo[0]) { if (contentScrollTop <= this.titlesInfo[0]) {
activeTitleIndex = 0; activeTitleIndex = 0;