Refactored all functionality into one function. Changed margin-top.
This commit is contained in:
parent
1031c61d0c
commit
bdba25b6f2
|
@ -156,6 +156,12 @@ let setupPageShow = window.setupPageShow = function (pageId) {
|
||||||
if ('IntersectionObserver' in window &&
|
if ('IntersectionObserver' in window &&
|
||||||
'IntersectionObserverEntry' in window &&
|
'IntersectionObserverEntry' in window &&
|
||||||
'intersectionRatio' in window.IntersectionObserverEntry.prototype) {
|
'intersectionRatio' in window.IntersectionObserverEntry.prototype) {
|
||||||
|
addPageHighlighting();
|
||||||
|
}
|
||||||
|
|
||||||
|
function addPageHighlighting() {
|
||||||
|
let $pageNav = null;
|
||||||
|
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
// fetch all the headings.
|
// fetch all the headings.
|
||||||
let headings = document.querySelector('.page-content').querySelectorAll('h1, h2, h3, h4, h5, h6');
|
let headings = document.querySelector('.page-content').querySelectorAll('h1, h2, h3, h4, h5, h6');
|
||||||
|
@ -164,15 +170,13 @@ let setupPageShow = window.setupPageShow = function (pageId) {
|
||||||
addNavObserver(headings);
|
addNavObserver(headings);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
let $pageNav = null;
|
|
||||||
function addNavObserver(headings) {
|
function addNavObserver(headings) {
|
||||||
// Setup the intersection observer.
|
// Setup the intersection observer.
|
||||||
// margin top = -25px to trigger the threshold change before the heading
|
// margin top = -35px to trigger the threshold change before the heading
|
||||||
// has completely left the viewport on the top.
|
// has completely left the viewport on the top.
|
||||||
let intersectOpts = {
|
let intersectOpts = {
|
||||||
rootMargin: '-25px 0px 0px 0px',
|
rootMargin: '-35px 0px 0px 0px',
|
||||||
threshold: 1.0
|
threshold: 1.0
|
||||||
}
|
}
|
||||||
$pageNav = $('.sidebar-page-nav');
|
$pageNav = $('.sidebar-page-nav');
|
||||||
|
@ -202,7 +206,7 @@ let setupPageShow = window.setupPageShow = function (pageId) {
|
||||||
$pageNav.find('a').removeClass('current-heading');
|
$pageNav.find('a').removeClass('current-heading');
|
||||||
$pageNav.find('a[href="#' + elementId + '"]').addClass('current-heading');
|
$pageNav.find('a[href="#' + elementId + '"]').addClass('current-heading');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = setupPageShow;
|
module.exports = setupPageShow;
|
Loading…
Reference in New Issue