feat: add scroll style settings in _config.yml
This commit is contained in:
parent
d563822005
commit
8ed99ba389
|
@ -37,9 +37,15 @@ style:
|
||||||
# First screen
|
# First screen
|
||||||
first_screen:
|
first_screen:
|
||||||
enable: false
|
enable: false
|
||||||
background_img: /images/bg.svg
|
background_img: /images/bg.svg # You can use local image or image external link
|
||||||
description: Keep writing and Keep loving.
|
description: Keep writing and Keep loving.
|
||||||
|
|
||||||
|
scroll:
|
||||||
|
progress_bar:
|
||||||
|
enable: false
|
||||||
|
percent:
|
||||||
|
enable: false
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
# Social contact link
|
# Social contact link
|
||||||
|
|
|
@ -17,13 +17,12 @@
|
||||||
// scrollTo: true,
|
// scrollTo: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
document.addEventListener('pjax:send', () => {
|
document.addEventListener('pjax:send', () => {
|
||||||
KEEP.utils.loadingProgressBarStart();
|
KEEP.utils.pjaxProgressBarStart();
|
||||||
});
|
});
|
||||||
|
|
||||||
document.addEventListener('pjax:complete', () => {
|
document.addEventListener('pjax:complete', () => {
|
||||||
KEEP.utils.loadingProgressBarEnd();
|
KEEP.utils.pjaxProgressBarEnd();
|
||||||
pjax.executeScripts(document.querySelectorAll('script[data-pjax], .pjax script'));
|
pjax.executeScripts(document.querySelectorAll('script[data-pjax], .pjax script'));
|
||||||
KEEP.refresh();
|
KEEP.refresh();
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
<div class="progress-bar-container">
|
<div class="progress-bar-container">
|
||||||
|
<% if (theme.style.scroll.progress_bar.enable === true) { %>
|
||||||
<span class="scroll-progress-bar"></span>
|
<span class="scroll-progress-bar"></span>
|
||||||
|
<% } %>
|
||||||
|
|
||||||
<% if (theme.pjax.enable === true) { %>
|
<% if (theme.pjax.enable === true) { %>
|
||||||
<span class="pjax-progress-bar"></span>
|
<span class="pjax-progress-bar"></span>
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
<div class="side-tools-container">
|
<div class="side-tools-container">
|
||||||
|
|
||||||
<ul class="side-tools-list">
|
<ul class="side-tools-list">
|
||||||
<li class="tools-item tool-font-adjust-plus flex-center">
|
<li class="tools-item tool-font-adjust-plus flex-center">
|
||||||
<i class="fas fa-search-plus"></i>
|
<i class="fas fa-search-plus"></i>
|
||||||
|
@ -29,18 +28,26 @@
|
||||||
</li>
|
</li>
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|
||||||
|
<% if (theme.style.scroll.percent.enable !== true) { %>
|
||||||
<li class="tools-item tool-scroll-to-top flex-center">
|
<li class="tools-item tool-scroll-to-top flex-center">
|
||||||
<i class="fas fa-arrow-up"></i>
|
<i class="fas fa-arrow-up"></i>
|
||||||
</li>
|
</li>
|
||||||
|
<% } %>
|
||||||
|
|
||||||
<li class="tools-item tool-scroll-to-bottom flex-center">
|
<li class="tools-item tool-scroll-to-bottom flex-center">
|
||||||
<i class="fas fa-arrow-down"></i>
|
<i class="fas fa-arrow-down"></i>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<ul>
|
<ul class="exposed-tools-list">
|
||||||
<li class="tools-item tool-toggle-show flex-center">
|
<li class="tools-item tool-toggle-show flex-center">
|
||||||
<i class="fas fa-cog fa-spin"></i>
|
<i class="fas fa-cog fa-spin"></i>
|
||||||
</li>
|
</li>
|
||||||
|
<% if (theme.style.scroll.percent.enable === true) { %>
|
||||||
|
<li class="tools-item tool-scroll-to-top flex-center">
|
||||||
|
<i class="arrow-up fas fa-arrow-up"></i>
|
||||||
|
<span class="percent"></span>
|
||||||
|
</li>
|
||||||
|
<% } %>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
width: 100%;
|
width: 100%;
|
||||||
z-index: $z-index-9;
|
z-index: $z-index-9;
|
||||||
|
|
||||||
|
if (hexo-config('pjax.enable') == true) {
|
||||||
|
|
||||||
.pjax-progress-bar {
|
.pjax-progress-bar {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
top: 0;
|
||||||
|
@ -49,6 +51,10 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hexo-config('style.scroll.progress_bar.enable') == true) {
|
||||||
|
|
||||||
.scroll-progress-bar {
|
.scroll-progress-bar {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
top: 0;
|
||||||
|
@ -61,8 +67,11 @@
|
||||||
z-index: $z-index-7;
|
z-index: $z-index-7;
|
||||||
|
|
||||||
&.hide {
|
&.hide {
|
||||||
transition: none;
|
//transition: none;
|
||||||
visibility: hidden;
|
display: none;
|
||||||
|
//visibility: hidden !important;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,10 +62,45 @@ $tools-item-border-radius = 1px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
&.show {
|
&.show {
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
transform: translateX(0);
|
transform: translateX(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.exposed-tools-list {
|
||||||
|
|
||||||
|
if (hexo-config('style.scroll.percent.enable') == true) {
|
||||||
|
.tool-scroll-to-top {
|
||||||
|
display: none;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
transition();
|
||||||
|
|
||||||
|
.arrow-up {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
|
||||||
|
.percent {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.arrow-up {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.percent {
|
||||||
|
display: flex;
|
||||||
|
font-size: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ KEEP.initBack2Top = () => {
|
||||||
|
|
||||||
...KEEP.utils,
|
...KEEP.utils,
|
||||||
|
|
||||||
back2TopButton_dom: document.querySelector('.tool-scroll-to-top'),
|
|
||||||
back2BottomButton_dom: document.querySelector('.tool-scroll-to-bottom'),
|
back2BottomButton_dom: document.querySelector('.tool-scroll-to-bottom'),
|
||||||
|
|
||||||
back2top() {
|
back2top() {
|
||||||
|
|
|
@ -9,25 +9,39 @@ KEEP.initUtils = () => {
|
||||||
scrollProgressBar_dom: document.querySelector('.scroll-progress-bar'),
|
scrollProgressBar_dom: document.querySelector('.scroll-progress-bar'),
|
||||||
pjaxProgressBar_dom: document.querySelector('.pjax-progress-bar'),
|
pjaxProgressBar_dom: document.querySelector('.pjax-progress-bar'),
|
||||||
pjaxProgressIcon_dom: document.querySelector('.pjax-progress-icon'),
|
pjaxProgressIcon_dom: document.querySelector('.pjax-progress-icon'),
|
||||||
|
back2TopButton_dom: document.querySelector('.tool-scroll-to-top'),
|
||||||
|
|
||||||
innerHeight: window.innerHeight,
|
innerHeight: window.innerHeight,
|
||||||
loadingProgressBarTimer: null,
|
pjaxProgressBarTimer: null,
|
||||||
prevScrollValue: 0,
|
prevScrollValue: 0,
|
||||||
defaultFontSize: 0,
|
defaultFontSize: 0,
|
||||||
|
|
||||||
|
isHasScrollProgressBar: KEEP.theme_config.style.scroll.progress_bar.enable === true,
|
||||||
|
isHasScrollPercent: KEEP.theme_config.style.scroll.percent.enable === true,
|
||||||
|
|
||||||
// Scroll Style Handle
|
// Scroll Style Handle
|
||||||
styleHandleWhenScroll() {
|
styleHandleWhenScroll() {
|
||||||
const scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
|
const scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
|
||||||
const scrollHeight = document.body.scrollHeight || document.documentElement.scrollHeight;
|
const scrollHeight = document.body.scrollHeight || document.documentElement.scrollHeight;
|
||||||
const clientHeight = window.innerHeight || document.documentElement.clientHeight;
|
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).toFixed(0);
|
||||||
const ProgressPercent = (scrollTop / (scrollHeight - clientHeight) * 100).toFixed(3);
|
|
||||||
|
|
||||||
if (this.scrollProgressBar_dom) {
|
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}%`;
|
this.scrollProgressBar_dom.style.width = `${ProgressPercent}%`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.isHasScrollPercent) {
|
||||||
|
const percent_dom = this.back2TopButton_dom.querySelector('.percent');
|
||||||
|
if (percent === '0') {
|
||||||
|
this.back2TopButton_dom.style.display = 'none';
|
||||||
|
} else {
|
||||||
|
this.back2TopButton_dom.style.display = 'flex';
|
||||||
|
percent_dom.innerHTML = percent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// hide header handle
|
// hide header handle
|
||||||
if (scrollTop > this.prevScrollValue && scrollTop > this.innerHeight) {
|
if (scrollTop > this.prevScrollValue && scrollTop > this.innerHeight) {
|
||||||
this.pageTop_dom.classList.add('hide');
|
this.pageTop_dom.classList.add('hide');
|
||||||
|
@ -41,7 +55,9 @@ KEEP.initUtils = () => {
|
||||||
registerWindowScroll() {
|
registerWindowScroll() {
|
||||||
window.addEventListener('scroll', () => {
|
window.addEventListener('scroll', () => {
|
||||||
// style handle when scroll
|
// style handle when scroll
|
||||||
|
if (this.isHasScrollPercent || this.isHasScrollProgressBar) {
|
||||||
this.styleHandleWhenScroll();
|
this.styleHandleWhenScroll();
|
||||||
|
}
|
||||||
|
|
||||||
// TOC scroll handle
|
// TOC scroll handle
|
||||||
if (KEEP.theme_config.toc.enable && KEEP.utils.hasOwnProperty('findActiveIndexByTOC')) {
|
if (KEEP.theme_config.toc.enable && KEEP.utils.hasOwnProperty('findActiveIndexByTOC')) {
|
||||||
|
@ -238,19 +254,22 @@ KEEP.initUtils = () => {
|
||||||
},
|
},
|
||||||
|
|
||||||
// loading progress bar start
|
// loading progress bar start
|
||||||
loadingProgressBarStart() {
|
pjaxProgressBarStart() {
|
||||||
this.loadingProgressBarTimer && clearInterval(this.loadingProgressBarTimer);
|
this.pjaxProgressBarTimer && clearInterval(this.pjaxProgressBarTimer);
|
||||||
this.pjaxProgressBar_dom.style.width = '0';
|
if (this.isHasScrollProgressBar) {
|
||||||
this.scrollProgressBar_dom.classList.add('hide');
|
this.scrollProgressBar_dom.classList.add('hide');
|
||||||
|
}
|
||||||
|
|
||||||
|
this.pjaxProgressBar_dom.style.width = '0';
|
||||||
this.pjaxProgressIcon_dom.classList.add('show');
|
this.pjaxProgressIcon_dom.classList.add('show');
|
||||||
|
|
||||||
let width = 5;
|
let width = 1;
|
||||||
const maxWidth = 99;
|
const maxWidth = 99;
|
||||||
|
|
||||||
this.pjaxProgressBar_dom.classList.add('show');
|
this.pjaxProgressBar_dom.classList.add('show');
|
||||||
this.pjaxProgressBar_dom.style.width = width + '%';
|
this.pjaxProgressBar_dom.style.width = width + '%';
|
||||||
|
|
||||||
this.loadingProgressBarTimer = setInterval(() => {
|
this.pjaxProgressBarTimer = setInterval(() => {
|
||||||
width += 5;
|
width += 5;
|
||||||
if (width > maxWidth) width = maxWidth;
|
if (width > maxWidth) width = maxWidth;
|
||||||
this.pjaxProgressBar_dom.style.width = width + '%';
|
this.pjaxProgressBar_dom.style.width = width + '%';
|
||||||
|
@ -258,14 +277,17 @@ KEEP.initUtils = () => {
|
||||||
},
|
},
|
||||||
|
|
||||||
// loading progress bar end
|
// loading progress bar end
|
||||||
loadingProgressBarEnd() {
|
pjaxProgressBarEnd() {
|
||||||
this.loadingProgressBarTimer && clearInterval(this.loadingProgressBarTimer);
|
this.pjaxProgressBarTimer && clearInterval(this.pjaxProgressBarTimer);
|
||||||
this.pjaxProgressBar_dom.style.width = '100%';
|
this.pjaxProgressBar_dom.style.width = '100%';
|
||||||
|
|
||||||
const tempTimeout = setTimeout(() => {
|
const tempTimeout = setTimeout(() => {
|
||||||
this.pjaxProgressBar_dom.classList.remove('show');
|
this.pjaxProgressBar_dom.classList.remove('show');
|
||||||
this.pjaxProgressIcon_dom.classList.remove('show');
|
this.pjaxProgressIcon_dom.classList.remove('show');
|
||||||
|
|
||||||
|
if (this.isHasScrollProgressBar) {
|
||||||
this.scrollProgressBar_dom.classList.remove('hide');
|
this.scrollProgressBar_dom.classList.remove('hide');
|
||||||
|
}
|
||||||
clearTimeout(tempTimeout);
|
clearTimeout(tempTimeout);
|
||||||
}, 200);
|
}, 200);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue