Skip to content

Commit

Permalink
feat: add back-to-top button (alshedivat#2427)
Browse files Browse the repository at this point in the history
slove alshedivat#2425 

Demo:

<img width="1643" alt="image"
src="https://github.com/alshedivat/al-folio/assets/119845914/ea73b84b-1d09-4af8-b1ba-6090595f5ab7">

---------

Signed-off-by: simonwei97 <simonwei977@gmail.com>
Signed-off-by: Simonwei97 <119845914+simonwei97@users.noreply.github.com>
  • Loading branch information
simonwei97 authored and HaukeCornell committed Jul 8, 2024
1 parent 9958db2 commit ca49e5b
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions _includes/scripts/back_to_top.liquid
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<script src="{{ '/assets/js/vanilla-back-to-top.min.js' | relative_url | bust_file_cache }}"></script>
<script>
addBackToTop();
</script>
1 change: 1 addition & 0 deletions _layouts/default.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,6 @@
{% include scripts/wechatModal.liquid %}
{% include scripts/imageLayouts.liquid %}
{% include scripts/jekyll_tabs.liquid %}
{% include scripts/back_to_top.liquid %}
</body>
</html>
19 changes: 19 additions & 0 deletions _sass/_themes.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
--global-divider-color: rgba(0, 0, 0, 0.1);
--global-card-bg-color: #{$white-color};
--global-highlight-color: #{$red-color-dark};
--global-back-to-top-bg-color: #{$black-color};
--global-back-to-top-text-color: #{$white-color};

--global-tip-block: #42b983;
--global-tip-block-bg: #e2f5ec;
Expand Down Expand Up @@ -51,6 +53,16 @@
.repo-img-dark {
display: none;
}

#back-to-top {
color: var(--global-back-to-top-text-color);
background: var(--global-back-to-top-bg-color);
bottom: $back-to-top-bottom;
right: $back-to-top-right;
height: $back-to-top-height;
width: $back-to-top-width;
z-index: $back-to-top-z-index;
}
}

html[data-theme="dark"] {
Expand All @@ -67,6 +79,8 @@ html[data-theme="dark"] {
--global-distill-app-color: #{$grey-color-light};
--global-divider-color: #424246;
--global-card-bg-color: #{$grey-900};
--global-back-to-top-bg-color: #{$white-color};
--global-back-to-top-text-color: #{$black-color};

--global-tip-block: #42b983;
--global-tip-block-bg: #e2f5ec;
Expand Down Expand Up @@ -103,6 +117,11 @@ html[data-theme-setting="dark"] {
#light-toggle-light {
display: none;
}

#back-to-top {
color: var(--global-back-to-top-text-color);
background: var(--global-back-to-top-bg-color);
}
}

html[data-theme-setting="light"] {
Expand Down
8 changes: 8 additions & 0 deletions _sass/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,11 @@ $fa-font-path: "../webfonts";

// Tabler icons location
$ti-font-path: "../fonts";

// Back To Top button config
$back-to-top-z-index: 10;
$back-to-top-bottom: 50px;
$back-to-top-right: 50px;
$back-to-top-diameter: 56px;
$back-to-top-height: $back-to-top-diameter;
$back-to-top-width: $back-to-top-diameter;
1 change: 1 addition & 0 deletions assets/js/vanilla-back-to-top.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ca49e5b

Please sign in to comment.