Skip to content

Commit

Permalink
ADD: scrolling to active TOC if TOC > viewport.
Browse files Browse the repository at this point in the history
Scrolling to center active TOC element if TOC content is taller then viewport.
  • Loading branch information
ivan-nginx authored Sep 23, 2017
1 parent 61086aa commit 619c49e
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions source/js/src/post-details.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ $(document).ready(function () {

removeCurrentActiveClass();
$currentActiveElement.addClass('active-current');

// Scrolling to center active TOC element if TOC content is taller then viewport.
$tocElement.scrollTop($currentActiveElement.offset().top - $tocElement.offset().top + $tocElement.scrollTop() - ($tocElement.height() / 2));
})
.on('clear.bs.scrollspy', removeCurrentActiveClass);

Expand Down

0 comments on commit 619c49e

Please sign in to comment.