-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathprogressbar.html
More file actions
23 lines (19 loc) · 883 Bytes
/
Copy pathprogressbar.html
File metadata and controls
23 lines (19 loc) · 883 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<div id="progress-bar" style="width: 0%; height:1px; background-color: rgb(89 127 235); position: fixed; top: 0px; transform: scaleY(0.5); transform-origin: top left; z-index: 2000;"></div>
<script id="progressbar" type="text/javascript">
document.addEventListener("DOMContentLoaded", function () {
const bar = document.querySelector("#progress-bar");
const post = document.querySelector("#quarto-content");
const html = document.documentElement;
if (!bar || !post) {
return;
}
function updateProgress() {
const height = post.scrollHeight + post.offsetTop;
const scrollable = height - html.clientHeight;
bar.style.width = (scrollable > 0 ? (html.scrollTop / scrollable) * 100 : 0) + "%";
}
updateProgress();
window.addEventListener("scroll", updateProgress, { passive: true });
window.addEventListener("resize", updateProgress);
});
</script>