feat: click to top (#84)
This commit is contained in:
parent
ad83aa4302
commit
ffb0e94ff5
4 changed files with 68 additions and 1 deletions
18
_includes/extensions/click-to-top.html
Normal file
18
_includes/extensions/click-to-top.html
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
<div id="click-to-top" class="click-to-top">
|
||||||
|
<i class="fa fa-arrow-up"></i>
|
||||||
|
</div>
|
||||||
|
<script>
|
||||||
|
(function () {
|
||||||
|
const clickToTop = document.getElementById('click-to-top');
|
||||||
|
window.addEventListener('scroll', () => {
|
||||||
|
if (window.scrollY > 100) {
|
||||||
|
clickToTop.classList.add('show')
|
||||||
|
}else {
|
||||||
|
clickToTop.classList.remove('show')
|
||||||
|
}
|
||||||
|
});
|
||||||
|
clickToTop.addEventListener('click', () => {
|
||||||
|
window.smoothScrollTo(0);
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
</script>
|
|
@ -13,6 +13,8 @@
|
||||||
|
|
||||||
{%- include extensions/theme-toggle.html -%}
|
{%- include extensions/theme-toggle.html -%}
|
||||||
|
|
||||||
|
{%- include extensions/click-to-top.html -%}
|
||||||
|
|
||||||
<main class="page-content" aria-label="Content">
|
<main class="page-content" aria-label="Content">
|
||||||
<div class="wrapper">
|
<div class="wrapper">
|
||||||
{{ content }}
|
{{ content }}
|
||||||
|
|
46
_sass/misc/click-to-top.scss
Normal file
46
_sass/misc/click-to-top.scss
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
.click-to-top {
|
||||||
|
transition: 0.3s;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
position: fixed;
|
||||||
|
width: 64px;
|
||||||
|
height: 64px;
|
||||||
|
border-radius: 32px;
|
||||||
|
right: 60px;
|
||||||
|
bottom: 48px;
|
||||||
|
background: white;
|
||||||
|
cursor: pointer;
|
||||||
|
opacity: 0;
|
||||||
|
transform: translateY(10px);
|
||||||
|
box-shadow: 0 2px 15px rgba(0, 0, 0, 0.15);
|
||||||
|
font-size: 24px;
|
||||||
|
user-select: none;
|
||||||
|
|
||||||
|
@include media-query(1024px) {
|
||||||
|
width: 48px;
|
||||||
|
height: 48px;
|
||||||
|
border-radius: 24px;
|
||||||
|
right: 35px;
|
||||||
|
font-size: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@include media-query($on-palm) {
|
||||||
|
width: 36px;
|
||||||
|
height: 36px;
|
||||||
|
border-radius: 18px;
|
||||||
|
right: 20px;
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.click-to-top.show {
|
||||||
|
opacity: 1;
|
||||||
|
transform: translateY(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
html[data-theme="dark"] {
|
||||||
|
.click-to-top {
|
||||||
|
background: #34323D;
|
||||||
|
}
|
||||||
|
}
|
|
@ -65,5 +65,6 @@ $on-laptop: 800px !default;
|
||||||
"misc/article-menu",
|
"misc/article-menu",
|
||||||
"misc/common-list",
|
"misc/common-list",
|
||||||
"misc/google-translate",
|
"misc/google-translate",
|
||||||
"misc/gitment"
|
"misc/gitment",
|
||||||
|
"misc/click-to-top"
|
||||||
;
|
;
|
||||||
|
|
Loading…
Reference in a new issue