Skip to content

Commit e4dd5ae

Browse files
committed
TOC: scrollIntoView для автопрокрутки к активному элементу
1 parent 19454c6 commit e4dd5ae

1 file changed

Lines changed: 1 addition & 11 deletions

File tree

_layouts/post.html

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -208,17 +208,7 @@ <h3>{{ t.post_discussion }}</h3>
208208
});
209209

210210
if (activeLink) {
211-
var sidebar = document.getElementById('toc-sidebar');
212-
var linkTop = activeLink.offsetTop - sidebar.offsetTop;
213-
var linkBottom = linkTop + activeLink.offsetHeight;
214-
var scrollTop = sidebar.scrollTop;
215-
var viewHeight = sidebar.clientHeight;
216-
217-
if (linkTop < scrollTop + 40) {
218-
sidebar.scrollTo({top: linkTop - 40, behavior: 'smooth'});
219-
} else if (linkBottom > scrollTop + viewHeight - 40) {
220-
sidebar.scrollTo({top: linkBottom - viewHeight + 40, behavior: 'smooth'});
221-
}
211+
activeLink.scrollIntoView({block: 'nearest', behavior: 'smooth'});
222212
}
223213
}
224214

0 commit comments

Comments
 (0)