LeaveItFork/layouts/partials/toc.html

38 lines
1.2 KiB
HTML

<div class="post-toc" id="post-toc">
<h2 class="post-toc-title">{{ T "toc" }}</h2>
{{ $globalAutoCollapseToc := .Site.Params.autoCollapseToc | default false }}
<div class="post-toc-content{{ if not (or .Params.autoCollapseToc (and $globalAutoCollapseToc (ne .Params.autoCollapseToc false))) }} always-active{{ end }}">
{{.TableOfContents}}
</div>
</div>
<script type="text/javascript">
window.onload = function () {
var fix = $('.post-toc');
var end = $('.post-comment');
var fixTop = fix.offset().top, fixHeight = fix.height();
var endTop, miss;
var offsetTop = fix[0].offsetTop;
$(window).scroll(function () {
var docTop = Math.max(document.body.scrollTop, document.documentElement.scrollTop);
if (end.length > 0) {
endTop = end.offset().top;
miss = endTop - docTop - fixHeight;
}
if (fixTop < docTop) {
fix.css({ 'position': 'fixed' });
if ((end.length > 0) && (endTop < (docTop + fixHeight))) {
fix.css({ top: miss });
} else {
fix.css({ top: 0 });
}
} else {
fix.css({ 'position': 'absolute' });
fix.css({ top: offsetTop });
}
})
}
</script>