12 lines
555 B
JavaScript
12 lines
555 B
JavaScript
|
window.addEventListener("scroll", () => {
|
||
|
var winScroll = document.body.scrollTop || document.documentElement.scrollTop;
|
||
|
var height = document.documentElement.scrollHeight - document.documentElement.clientHeight;
|
||
|
var scrolled = (winScroll / height) * 100;
|
||
|
document.getElementById('progress').style.width = scrolled + "%";
|
||
|
|
||
|
const toTop = document.getElementById('totop');
|
||
|
|
||
|
if ((window.scrollY > 0 && !toTop.classList.contains("show")) || (window.scrollY <= 0 && toTop.classList.contains("show"))) {
|
||
|
toTop.classList.toggle("show");
|
||
|
}
|
||
|
});
|