add progressbar

This commit is contained in:
Wonderfall 2022-07-29 00:07:11 +02:00
parent 0a140a1a12
commit 13876beb0a
3 changed files with 25 additions and 3 deletions

View File

@ -171,3 +171,12 @@ body:not(.dark) #sun {
.logo-switches { .logo-switches {
flex-wrap: inherit; flex-wrap: inherit;
} }
#progressBar {
--scrollAmount: 0%;
width: var(--scrollAmount);
height: 3px;
background-color: rgb(0, 128, 128);
position: fixed;
z-index: 9999;
}

View File

@ -107,13 +107,23 @@ function showCodeCopyButtons() {
function openToc() { function openToc() {
var toc = document.getElementById("toc"); var toc = document.getElementById("toc");
if (toc && window.innerWidth > 1500 && window.innerHeight > 800) { if (window.innerWidth > 1500 && window.innerHeight > 800) {
toc.open = true; 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(); initializeMenu();
openToc();
if (params.scrollToTop) scrollToTop(); if (params.scrollToTop) scrollToTop();
if (params.themeToggle) themeToggle(); if (params.themeToggle) themeToggle();
if (params.showCodeCopyButtons) showCodeCopyButtons(); if (params.showCodeCopyButtons) showCodeCopyButtons();
if (document.getElementById("toc")) openToc();
if (document.getElementById("progressBar")) progressBar();

View File

@ -11,6 +11,9 @@
{{- end }} {{- end }}
<header class="header"> <header class="header">
{{- if .IsPage }}
<div id="progressBar"></div>
{{- end }}
<nav class="nav"> <nav class="nav">
<div class="logo"> <div class="logo">
{{- $label_text := (site.Params.label.text | default site.Title) }} {{- $label_text := (site.Params.label.text | default site.Title) }}