Skip to content
This repository was archived by the owner on Mar 9, 2022. It is now read-only.

Commit

Permalink
feat(fixed-btns): add title for fixed buttons (#176)
Browse files Browse the repository at this point in the history
  • Loading branch information
dillonzq authored Mar 16, 2020
1 parent 0ca8a4c commit 80db783
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 29 deletions.
9 changes: 5 additions & 4 deletions assets/css/_partial/_fixed-button.scss
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#fixed-buttons {
display: none;
}

.fixed-button {
display: none;
overflow: hidden;
width: auto;
z-index: 100;
position: fixed;
top: auto;
left: auto;
right: 1.5rem;
font-size: 1rem;
line-height: 1.3rem;
Expand Down Expand Up @@ -36,6 +36,7 @@
}

#top-button {
display: block;
bottom: 1.5rem;
}

Expand Down
2 changes: 1 addition & 1 deletion assets/js/theme.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/js/theme.min.js.map

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions i18n/en.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# Translations for English
# https://gohugo.io/content-management/multilingual/#translation-of-strings

# === baseof ==
[backToTop]
other = "Back to Top"

[viewComments]
other = "View Comments"
# === baseof ==

# === Post ===
[posts]
other = "Posts"
Expand Down
8 changes: 8 additions & 0 deletions i18n/fr.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# Translations for French
# https://gohugo.io/content-management/multilingual/#translation-of-strings

# === baseof ==
[backToTop]
other = "Retour en Haut"

[viewComments]
other = "Afficher les Commentaires"
# === baseof ==

# === Post ===
[posts]
other = "Posts"
Expand Down
8 changes: 8 additions & 0 deletions i18n/zh-CN.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# Translations for Simplified Chinese
# https://gohugo.io/content-management/multilingual/#translation-of-strings

# === baseof ==
[backToTop]
other = "回到顶部"

[viewComments]
other = "查看评论"
# === baseof ==

# === Post ===
[posts]
other = "文章"
Expand Down
9 changes: 7 additions & 2 deletions layouts/_default/baseof.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,16 @@
{{- partial "footer.html" . -}}
</div>

<div id="fixed-btn-container">
<div id="fixed-buttons" class="animated faster">
{{- /* top button */ -}}
<a href="#" id="top-button" class="fixed-button animated faster">
<a href="#" id="top-button" class="fixed-button" title="{{ T `backToTop` }}">
<i class="fas fa-arrow-up fa-fw"></i>
</a>

{{- /* comment button */ -}}
<a href="#" id="comment-button" class="fixed-button" title="{{ T `viewComments` }}">
<i class="fas fa-comment fa-fw"></i>
</a>
</div>

{{- /* Load JavaScript scripts and CSS */ -}}
Expand Down

Large diffs are not rendered by default.

34 changes: 14 additions & 20 deletions src/js/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,15 +250,11 @@
});
const comments = document.getElementsByClassName('comment') || [];
if (comments.length) {
const container = document.getElementById('fixed-btn-container');
const button = document.createElement('a');
const button = document.getElementById('comment-button');
button.href = `#${comments[0].id}`;
button.id = 'comment-button';
button.className = 'fixed-button animated faster';
button.innerHTML = '<i class="fas fa-comment fa-fw"></i>';
container.appendChild(button);
button.style.display = 'block';
}
const buttons = document.getElementsByClassName('fixed-button');
const fixedButtons = document.getElementById('fixed-buttons');
const MIN_SCROLL = 10;
window.addEventListener('scroll', () => {
this.newScrollTop = this.util.getScrollTop();
Expand All @@ -272,20 +268,18 @@
header.classList.add('fadeInDown');
}
});
this.util.forEach(buttons, (button) => {
if (this.newScrollTop > 20) {
if (scroll > MIN_SCROLL) {
button.classList.remove('fadeIn');
button.classList.add('fadeOut');
} else if (scroll < - MIN_SCROLL) {
button.style.display = 'block';
button.classList.remove('fadeOut');
button.classList.add('fadeIn');
}
} else {
button.style.display = 'none';
if (this.newScrollTop > 20) {
if (scroll > MIN_SCROLL) {
fixedButtons.classList.remove('fadeIn');
fixedButtons.classList.add('fadeOut');
} else if (scroll < - MIN_SCROLL) {
fixedButtons.style.display = 'block';
fixedButtons.classList.remove('fadeOut');
fixedButtons.classList.add('fadeIn');
}
});
} else {
fixedButtons.style.display = 'none';
}
if (!this._scrollTimeout) {
this._scrollTimeout = window.setTimeout(() => {
this._scrollTimeout = null;
Expand Down

0 comments on commit 80db783

Please sign in to comment.