in site-ui/src/js/01-on-this-page.js [56:85]
function onScroll () {
// NOTE doc.parentNode.offsetTop ~= doc.parentNode.getBoundingClientRect().top + window.pageYOffset
//var targetPosition = doc.parentNode.offsetTop
// NOTE no need to compensate wheen using spacer above [id] elements
var targetPosition = 0
var activeFragment
headings.some(function (heading) {
if (Math.floor(heading.getBoundingClientRect().top) <= targetPosition) {
activeFragment = '#' + heading.id
} else {
return true
}
})
if (activeFragment) {
if (activeFragment !== lastActiveFragment) {
if (lastActiveFragment) {
links[lastActiveFragment].classList.remove('is-active')
}
var activeLink = links[activeFragment]
activeLink.classList.add('is-active')
if (menu.scrollHeight > menu.offsetHeight) {
menu.scrollTop = Math.max(0, activeLink.offsetTop + activeLink.offsetHeight - menu.offsetHeight)
}
lastActiveFragment = activeFragment
}
} else if (lastActiveFragment) {
links[lastActiveFragment].classList.remove('is-active')
lastActiveFragment = undefined
}
}