Skip to content

Commit

Permalink
Merge pull request kunjgit#3987 from zalabhavy/Scrolltotop
Browse files Browse the repository at this point in the history
Scroll to top button added
  • Loading branch information
kunjgit authored Jun 2, 2024
2 parents b9a9625 + 4dfc50d commit 70f7afa
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 31 deletions.
54 changes: 27 additions & 27 deletions assets/js/scroll.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
// let calcScrollValue = () => {
// let scrollProg = document.getElementById("progress");
// let pos = document.documentElement.scrollTop;
// let calcHeight =
// document.documentElement.scrollHeight -
// document.documentElement.clientHeight;
// let scrollValue = Math.round((pos * 100) / calcHeight);
// if (pos > 100) {
// scrollProg.style.display = "grid";
// } else {
// scrollProg.style.display = "none";
// }
// scrollProg.addEventListener("click", () => {
// document.documentElement.scrollTop = 0;
// });
// scrollProg.style.background = `conic-gradient(#6862e8 ${scrollValue}%, #d499de ${scrollValue}%)`;
// };
let calcScrollValue = () => {
let scrollProg = document.getElementById("progress");
let pos = document.documentElement.scrollTop;
let calcHeight =
document.documentElement.scrollHeight -
document.documentElement.clientHeight;
let scrollValue = Math.round((pos * 100) / calcHeight);
if (pos > 100) {
scrollProg.style.display = "grid";
} else {
scrollProg.style.display = "none";
}
scrollProg.addEventListener("click", () => {
document.documentElement.scrollTop = 0;
});
scrollProg.style.background = `conic-gradient(#6862e8 ${scrollValue}%, #d499de ${scrollValue}%)`;
};

// window.addEventListener('scroll', function() {
// var scrollToTopButton = document.getElementById('progress');
// if (window.pageYOffset > 200) {
// scrollToTopButton.style.display = 'block';
// } else {
// scrollToTopButton.style.display = 'none';
// }
// });
window.addEventListener('scroll', function() {
var scrollToTopButton = document.getElementById('progress');
if (window.pageYOffset > 200) {
scrollToTopButton.style.display = 'block';
} else {
scrollToTopButton.style.display = 'none';
}
});


// window.onscroll = calcScrollValue;
// window.onload = calcScrollValue;
window.onscroll = calcScrollValue;
window.onload = calcScrollValue;


const filled = document.querySelector(".filled");
Expand Down
8 changes: 4 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -376,14 +376,14 @@ <h2 id="total-contributors" style="text-align: center; font-family: 'Agency FB',
<div>
</div>

<!-- <button onclick="scrollToTop()" id="scrollToTopButton" title="Scroll to Top">
<button onclick="scrollToTop()" id="scrollToTopButton" title="Scroll to Top">
<ion-icon name="arrow-up-outline"></ion-icon>
</button> -->
</button>

<!-- SCROLL TO TOP BUTTON -->
<!-- <div id="progress">
<div id="progress">
<span id="progress-value">&#x1F815;</span>
</div> -->
</div>

</body>

Expand Down

0 comments on commit 70f7afa

Please sign in to comment.