mirror of
https://github.com/acid-info/nimbus-site.git
synced 2025-01-18 05:11:01 +00:00
35 lines
786 B
JavaScript
35 lines
786 B
JavaScript
(function() {
|
|
'use strict';
|
|
|
|
var header = document.getElementById('header');
|
|
if (!header) {
|
|
return;
|
|
}
|
|
var toc = document.getElementById('article-toc');
|
|
var tocTop = document.getElementById('article-toc-top');
|
|
var headerHeight = header.clientHeight;
|
|
|
|
if (!toc) return;
|
|
|
|
function updateSidebarPosition() {
|
|
var scrollTop = document.scrollingElement.scrollTop;
|
|
|
|
if (scrollTop > headerHeight) {
|
|
toc.classList.add('fixed');
|
|
} else {
|
|
toc.classList.remove('fixed');
|
|
}
|
|
}
|
|
|
|
window.addEventListener('scroll', function() {
|
|
window.requestAnimationFrame(updateSidebarPosition);
|
|
});
|
|
|
|
updateSidebarPosition();
|
|
|
|
tocTop.addEventListener('click', function(e) {
|
|
e.preventDefault();
|
|
document.scrollingElement.scrollTop = 0;
|
|
});
|
|
}());
|