From b7a0645751ddd01a7391f2041725267cf4a8a875 Mon Sep 17 00:00:00 2001 From: XPoet Date: Mon, 25 Jan 2021 11:12:01 +0800 Subject: [PATCH] fix: fixed where scrolling percent 0 does not hide --- source/css/layout/_partial/side-tools.styl | 8 -------- source/js/utils.js | 12 ++++++------ 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/source/css/layout/_partial/side-tools.styl b/source/css/layout/_partial/side-tools.styl index 6ad7677..1d298be 100644 --- a/source/css/layout/_partial/side-tools.styl +++ b/source/css/layout/_partial/side-tools.styl @@ -95,20 +95,12 @@ $tools-item-border-radius = 1px; display: flex; } - } - - .arrow-up, .percent { - transition-t("display", "5", "0.2", "linear"); - } - - .arrow-up { display: none; } - .percent { display: flex; font-size: 1rem; diff --git a/source/js/utils.js b/source/js/utils.js index cb84401..1e15ce2 100644 --- a/source/js/utils.js +++ b/source/js/utils.js @@ -26,23 +26,23 @@ KEEP.initUtils = () => { const scrollTop = document.body.scrollTop || document.documentElement.scrollTop; const scrollHeight = document.body.scrollHeight || document.documentElement.scrollHeight; const clientHeight = window.innerHeight || document.documentElement.clientHeight; - const percent = Math.round(scrollTop / (scrollHeight - clientHeight) * 100).toFixed(0); + + const percent = Math.round(scrollTop / (scrollHeight - clientHeight) * 100); if (this.isHasScrollProgressBar) { const ProgressPercent = (scrollTop / (scrollHeight - clientHeight) * 100).toFixed(3); - this.scrollProgressBar_dom.style.visibility = percent === '0' ? 'hidden' : 'visible'; + this.scrollProgressBar_dom.style.visibility = percent === 0 ? 'hidden' : 'visible'; this.scrollProgressBar_dom.style.width = `${ProgressPercent}%`; } if (this.isHasScrollPercent) { const percent_dom = this.back2TopButton_dom.querySelector('.percent'); - if (percent === '0') { - this.back2TopButton_dom.classList.remove('show'); - } if (percent !== percent || !isFinite(percent)) { + if (percent === 0 || percent === undefined) { this.back2TopButton_dom.classList.remove('show'); + } else { this.back2TopButton_dom.classList.add('show'); - percent_dom.innerHTML = percent; + percent_dom.innerHTML = percent.toFixed(0); } }