From: Dan Allen Date: Thu, 9 Apr 2020 10:10:15 +0000 (-0600) Subject: slighly tweak the thresholds for the scroll spy X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=7373030687d563a37e560108e4786d32b861cbdd;p=working%2Feg-antora.git slighly tweak the thresholds for the scroll spy --- diff --git a/src/js/02-on-this-page.js b/src/js/02-on-this-page.js index 9d24937..c568555 100644 --- a/src/js/02-on-this-page.js +++ b/src/js/02-on-this-page.js @@ -55,17 +55,13 @@ var buffer = getStyleValueAsInt(document.documentElement, 'fontSize') * 1.15 var targetPosition = article.offsetTop if (scrolledBy && window.innerHeight + scrolledBy + 2 >= document.documentElement.scrollHeight) { - if (lastActiveFragment) { - if (!Array.isArray(lastActiveFragment)) lastActiveFragment = [lastActiveFragment] - } else { - lastActiveFragment = [] - } + lastActiveFragment = Array.isArray(lastActiveFragment) ? lastActiveFragment : Array(lastActiveFragment || 0) var activeFragments = [] var lastIdx = headings.length - 1 headings.forEach(function (heading, idx) { var fragment = '#' + heading.id if (idx === lastIdx || - heading.getBoundingClientRect().top + getStyleValueAsInt(heading, 'paddingTop') >= targetPosition) { + heading.getBoundingClientRect().top + getStyleValueAsInt(heading, 'paddingTop') > targetPosition) { activeFragments.push(fragment) if (lastActiveFragment.indexOf(fragment) < 0) links[fragment].classList.add('is-active') } else if (~lastActiveFragment.indexOf(fragment)) { @@ -84,7 +80,7 @@ } var activeFragment headings.some(function (heading) { - if (targetPosition < heading.getBoundingClientRect().top + getStyleValueAsInt(heading, 'paddingTop') - buffer) { + if (heading.getBoundingClientRect().top + getStyleValueAsInt(heading, 'paddingTop') - buffer > targetPosition) { return true } activeFragment = '#' + heading.id