Commit 2f617a21 authored by bootstraponline's avatar bootstraponline

Scroll to closest header

parent adcf6c70
......@@ -147,6 +147,7 @@
var self = this;
self.tocifyWrapper = $('.tocify-wrapper');
self.extendPageScroll = true;
// 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
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) {
......@@ -1021,4 +1036,4 @@
});
})); //end of plugin
})); //end of plugin
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment