Skip to content

Commit

Permalink
add progressbar
Browse files Browse the repository at this point in the history
  • Loading branch information
Wonderfall committed Jul 28, 2022
1 parent 0a140a1 commit 13876be
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
9 changes: 9 additions & 0 deletions assets/css/common/header.css
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,12 @@ body:not(.dark) #sun {
.logo-switches {
flex-wrap: inherit;
}

#progressBar {
--scrollAmount: 0%;
width: var(--scrollAmount);
height: 3px;
background-color: rgb(0, 128, 128);
position: fixed;
z-index: 9999;
}
16 changes: 13 additions & 3 deletions assets/js/papermod.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,23 @@ function showCodeCopyButtons() {
function openToc() {
var toc = document.getElementById("toc");

if (toc && window.innerWidth > 1500 && window.innerHeight > 800) {
if (window.innerWidth > 1500 && window.innerHeight > 800) {
toc.open = true;
}
}

function progressBar() {
var bar = document.getElementById("progressBar");

document.addEventListener('scroll', () => {
var scrollPercent = document.documentElement.scrollTop / (document.documentElement.scrollHeight - window.innerHeight) * 100 + '%';
bar.style.setProperty("--scrollAmount", scrollPercent);
})
}

initializeMenu();
openToc();
if (params.scrollToTop) scrollToTop();
if (params.themeToggle) themeToggle();
if (params.showCodeCopyButtons) showCodeCopyButtons();
if (params.showCodeCopyButtons) showCodeCopyButtons();
if (document.getElementById("toc")) openToc();
if (document.getElementById("progressBar")) progressBar();
3 changes: 3 additions & 0 deletions layouts/partials/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
{{- end }}

<header class="header">
{{- if .IsPage }}
<div id="progressBar"></div>
{{- end }}
<nav class="nav">
<div class="logo">
{{- $label_text := (site.Params.label.text | default site.Title) }}
Expand Down

0 comments on commit 13876be

Please sign in to comment.