Skip to content

Commit

Permalink
Add support for css only scroll to top
Browse files Browse the repository at this point in the history
  • Loading branch information
1bl4z3r committed Jan 13, 2025
1 parent 19bd342 commit 4d32428
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 18 deletions.
8 changes: 7 additions & 1 deletion assets/js/scrollwatcher.js
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
const scroll=document.querySelector(".scroll-up"),rootElement=document.documentElement;function handleScroll(){rootElement.scrollTop/(rootElement.scrollHeight-rootElement.clientHeight)>.4?(scroll.classList.remove("hide"),scroll.classList.add("show")):(scroll.classList.add("hide"),scroll.classList.remove("show"))}document.addEventListener("scroll",handleScroll);
if (!(CSS.supports("animation-timeline: scroll()"))) {
const scroll = document.querySelector(".scroll-up"),rootElement = document.documentElement;
function handleScroll() {
rootElement.scrollTop / (rootElement.scrollHeight - rootElement.clientHeight) > .4 ? scroll.classList.add("show") : scroll.classList.remove("show");
}
document.addEventListener("scroll", handleScroll);
}
54 changes: 45 additions & 9 deletions assets/scss/_scrolltotop.scss
Original file line number Diff line number Diff line change
@@ -1,18 +1,54 @@
.scroll-up {
position: fixed;
bottom: 10%;
right: 2%;
z-index: 1;
opacity: 0;
transition: all 0.5s ease;
}
// Support for Experimental animation-timeline (https://developer.mozilla.org/en-US/docs/Web/CSS/animation-timeline)
@supports (animation-timeline: scroll()) {
.scroll-up {
animation-name: scrolltotop;
animation-timeline: scroll(y);
}

.hide {
opacity: 0;
transform: translateY(20px);
@keyframes scrolltotop {
0% {
opacity: 0;
position: fixed;
display: none;
}

45% {
opacity: 0;
position: fixed;
display: none;
transform: translateY(20px);
}

50% {
opacity: 1;
display: block;
position: fixed;
transform: translateY(0);
}

100% {
opacity: 1;
display: block;
position: fixed;
}
}
}

.show {
opacity: 1;
transform: translateY(0);
@supports not (animation-timeline: scroll()) {
.scroll-up {
position: fixed;
opacity: 0;
transition: all 0.5s ease;
transform: translateY(20px);
}

.show {
opacity: 1;
transform: translateY(0);
}
}
8 changes: 0 additions & 8 deletions content/posts/explaining-configs.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ Lastmod : 2025-03-12T20:30:30+05:30
- `robots` : Set to **false** to add page Disallow entry in robots.txt. Check [robots.txt](https://1bl4z3r.github.io/hermit-V2/robots.txt)
- `keywords` : Specify keywords for your article. It will be used to populate[ Structured Data Site names schema](https://developers.google.com/search/docs/appearance/site-names)

## Special Caveats

### Last Modified Date

If `ShowLastmod:true` :
Expand All @@ -121,12 +119,6 @@ If `ShowLastmod:true` :

If `ShowLastmod` is not provided. User response defaults to false. It is equivalent to providing `ShowLastmod:false`.

### LaTeX

LaTeX is implemented through Mathjax.
- If you are using this theme as a proper mathematical blog, enable `global_mathjax` to true in hugo.toml. It will enable Mathjax support site wide.
- Since Mathjax is a heavy script (>1 MB), it is not ideal to run Mathjax site wide, especially if you are in the above cohort. However, if you want to use mathematical formulas, you can set `mathjax : true` in Page frontmatter. It will enable mathjax for only that page only.

### Enable ScrolltoTop button

To enable scroll to top, **you must enable `scrollToTop` in hugo.toml and `scrolltotop` in Page Frontmatter**. This is to prevent scroll to top button from showing if the page has very less content. If you feel that for the content, you need scroll to top button, follow below steps:
Expand Down

0 comments on commit 4d32428

Please sign in to comment.