mirror of
https://github.com/danbulant/api_docs
synced 2026-06-05 23:51:04 +00:00
Merge pull request #56 from bootstraponline/scroll_to_closest_header
Scroll to closest header
This commit is contained in:
commit
e5cf1f2589
1 changed files with 16 additions and 1 deletions
|
|
@ -147,6 +147,7 @@
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
self.tocifyWrapper = $('.tocify-wrapper');
|
||||||
self.extendPageScroll = true;
|
self.extendPageScroll = true;
|
||||||
|
|
||||||
// Internal array that keeps track of all TOC items (Helps to recognize if there are duplicate TOC item strings)
|
// Internal array that keeps track of all TOC items (Helps to recognize if there are duplicate TOC item strings)
|
||||||
|
|
@ -703,6 +704,20 @@
|
||||||
// Highlights the corresponding list item
|
// Highlights the corresponding list item
|
||||||
elem.addClass(self.focusClass);
|
elem.addClass(self.focusClass);
|
||||||
|
|
||||||
|
// Scroll to highlighted element's header
|
||||||
|
var tocifyWrapper = self.tocifyWrapper;
|
||||||
|
var scrollToElem = $(elem).closest('.tocify-header');
|
||||||
|
|
||||||
|
var elementOffset = scrollToElem.offset().top,
|
||||||
|
wrapperOffset = tocifyWrapper.offset().top;
|
||||||
|
var offset = elementOffset - wrapperOffset;
|
||||||
|
|
||||||
|
if (offset >= $(window).height()) {
|
||||||
|
var scrollPosition = offset + tocifyWrapper.scrollTop();
|
||||||
|
tocifyWrapper.scrollTop(scrollPosition);
|
||||||
|
} else if (offset < 0) {
|
||||||
|
tocifyWrapper.scrollTop(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(self.options.scrollHistory) {
|
if(self.options.scrollHistory) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue