added scroll progress bar in single page template
This commit is contained in:
@@ -371,6 +371,8 @@ params:
|
|||||||
readTime:
|
readTime:
|
||||||
enable: true
|
enable: true
|
||||||
content: "min read"
|
content: "min read"
|
||||||
|
scrollprogress:
|
||||||
|
enable: true
|
||||||
|
|
||||||
# For translations
|
# For translations
|
||||||
terms:
|
terms:
|
||||||
|
|||||||
@@ -102,6 +102,13 @@
|
|||||||
</button>
|
</button>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
{{ if or (.Site.Params.singlePages.scrollprogress.enable | default true) (.Params.enableScrollProgress) }}
|
||||||
|
<div class="progress">
|
||||||
|
<div id="scroll-progress-bar" class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div>
|
||||||
|
</div>
|
||||||
|
<Script src="{{.Site.Params.staticPath}}/js/scrollProgressBar.js"></script>
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
var topScroll = document.getElementById("topScroll");
|
var topScroll = document.getElementById("topScroll");
|
||||||
window.onscroll = function() {scrollFunction()};
|
window.onscroll = function() {scrollFunction()};
|
||||||
|
|||||||
@@ -282,3 +282,25 @@
|
|||||||
transition: .5s;
|
transition: .5s;
|
||||||
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.2);
|
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Singlepage scroll progress start */
|
||||||
|
.progress {
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 2px;
|
||||||
|
background-color: var(--background-color);
|
||||||
|
z-index: 999;
|
||||||
|
}
|
||||||
|
|
||||||
|
.progress-bar {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
height: 100%;
|
||||||
|
background-color: var(--primary-color);
|
||||||
|
transition: width .2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Singlepage scroll progress end */
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
function getScrollPercent() {
|
||||||
|
const totalHeight = document.body.scrollHeight - window.innerHeight;
|
||||||
|
const scrolled = window.scrollY;
|
||||||
|
return (scrolled / totalHeight) * 100;
|
||||||
|
}
|
||||||
|
const scrollProgressBar = document.getElementById("scroll-progress-bar");
|
||||||
|
|
||||||
|
document.onscroll = function () {
|
||||||
|
var scrollPercent = Math.round(getScrollPercent());
|
||||||
|
scrollProgressBar.style.width = scrollPercent + "%";
|
||||||
|
scrollProgressBar.ariaValueNow = scrollPercent;
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user