Fix scrollspy on link clicking, and # for top of page (#2023)

This commit is contained in:
Erik Demaine 2019-01-15 08:08:41 -05:00 committed by Michael Rose
parent a974e45712
commit 1b7e8335fe
2 changed files with 6 additions and 3 deletions

View file

@ -82,7 +82,7 @@ $(document).ready(function() {
$(window).scroll(jQuery.throttle(250, function() { $(window).scroll(jQuery.throttle(250, function() {
// Don't run while smooth scrolling (from clicking on a link). // Don't run while smooth scrolling (from clicking on a link).
if (smoothScrolling) return; if (smoothScrolling) return;
var scrollTop = $(window).scrollTop() + 20; // 20 = offset var scrollTop = $(window).scrollTop() + 20 + 1; // 20 = offset
var links = []; var links = [];
$("nav.toc a").each(function() { $("nav.toc a").each(function() {
var link = $(this); var link = $(this);
@ -106,9 +106,12 @@ $(document).ready(function() {
if (links[i].href !== location.hash) { if (links[i].href !== location.hash) {
history.replaceState(null, null, links[i].href); history.replaceState(null, null, links[i].href);
} }
break; return;
} }
} }
if ('#' !== location.hash) {
history.replaceState(null, null, '#');
}
})); }));
// add lightbox class to all image links // add lightbox class to all image links

File diff suppressed because one or more lines are too long