Skip to content

Commit 1ae8e25

Browse files
committed
Update sidebar scroll handler
1 parent 5ead4c0 commit 1ae8e25

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

_includes/toc-footer.html

+10-5
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,19 @@
4141
}
4242
function calculatePositions() {
4343
positions = [];
44-
$(".docs-content h3,.docs-content h4").each(function() {
44+
$(".docs-content > div > h3,.docs-content > div > h4").each(function() {
4545
positions.push({
4646
el: $("#toc-item-"+$(this).attr('id')),
47-
pos: $(this).position().top+$(this).height()+parseInt($(this).css("marginTop"))
47+
orig: $(this),
48+
pos: $(this).offset().top +parseInt($(this).css("marginTop"))
4849
});
4950
});
5051
}
5152

5253
function getCurrentItem() {
54+
if (positions.length === 0) {
55+
return;
56+
}
5357
var top = $(window).scrollTop();
5458
var previous = positions[0].el;
5559
for (var i=0;i<positions.length;i++) {
@@ -75,9 +79,10 @@
7579
}
7680
$(window).resize(resizeWindow);
7781
$(window).on("scroll",scrollWindow);
78-
79-
resizeWindow();
80-
scrollWindow();
82+
setTimeout(function() {
83+
resizeWindow();
84+
scrollWindow();
85+
},500);
8186

8287
});
8388
</script>

0 commit comments

Comments
 (0)