Skip to content

Commit

Permalink
show progress on scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
sujaykundu777 committed Oct 31, 2021
1 parent 45d55f0 commit 160dc53
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 20 deletions.
1 change: 1 addition & 0 deletions _includes/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
<script src="{{site.url}}{{site.baseurl}}/assets/bower_components/nanobar/nanobar.min.js"></script>
<script src="{{site.url}}{{site.baseurl}}/assets/bower_components/typewrite/dist/typewrite.min.js"></script>
<script src="{{site.url}}{{site.baseurl}}/assets/js/search.js"></script>
<script src="{{site.url}}{{site.baseurl}}/assets/js/on-scroll-progress.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.20.1/moment.min.js"></script>
<script src="https://identity.netlify.com/v1/netlify-identity-widget.js"></script>

Expand Down
2 changes: 1 addition & 1 deletion _includes/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
</li> -->
</ul>
</nav>

<div id="progress-bar"></div>
<!-- Search Form -->
<div class="search-form-container">

Expand Down
19 changes: 0 additions & 19 deletions _posts/2021-08-14-this-post-is-using-github-codespaces.md

This file was deleted.

11 changes: 11 additions & 0 deletions _sass/devlopr.scss
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,17 @@ ol, ul {
background: #f69801;
}

/* On scroll progress bar */
#progress-bar {
background: linear-gradient(to right, #f69801 var(--progress), transparent 0);
height: 5px;
position: fixed;
width: 100%;
overflow: hidden;
z-index: 1;
margin-top: 25px;
}

body {
background-color: var(--main-background-color) !important;
color: var(--main-text-color) !important;
Expand Down
16 changes: 16 additions & 0 deletions assets/js/on-scroll-progress.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
document.addEventListener('scroll', _ => {
var docElem = document.documentElement;
var docBody = document.body;
var scrollTop = (docBody.scrollTop || docElem.scrollTop);
var height = docElem.scrollHeight - docElem.clientHeight;

progress = scrollTop / height * 100;

if ( progress > 0) {
progressBar = document.querySelector('#progress-bar');
progressBar.style.setProperty('--progress', progress + '%');
} else {
progressBar.style.setProperty('--progress', '0%');
}
});

0 comments on commit 160dc53

Please sign in to comment.