refactor: improve JS/HTML for button back2top (#1054)
The current "back to top" button is built by `<a>` tag, it would be more appropriate to replace it with the `<button>` tag.
This commit is contained in:
parent
bef2ac085e
commit
f6bf6d0864
2 changed files with 11 additions and 8 deletions
|
@ -3,15 +3,18 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function back2top() {
|
export function back2top() {
|
||||||
$(window).on('scroll', () => {
|
const $window = $(window);
|
||||||
if ($(window).scrollTop() > 50) {
|
const $btn = $('#back-to-top');
|
||||||
$('#back-to-top').fadeIn();
|
|
||||||
|
$window.on('scroll', () => {
|
||||||
|
if ($window.scrollTop() > 50) {
|
||||||
|
$btn.fadeIn();
|
||||||
} else {
|
} else {
|
||||||
$('#back-to-top').fadeOut();
|
$btn.fadeOut();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#back-to-top').on('click', () => {
|
$btn.on('click', () => {
|
||||||
window.scrollTo(0, 0);
|
$window.scrollTop(0);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,9 +34,9 @@ layout: compress
|
||||||
|
|
||||||
<div id="mask"></div>
|
<div id="mask"></div>
|
||||||
|
|
||||||
<a id="back-to-top" href="#" aria-label="back-to-top" class="btn btn-lg btn-box-shadow" role="button">
|
<button id="back-to-top" aria-label="back-to-top" class="btn btn-lg btn-box-shadow">
|
||||||
<i class="fas fa-angle-up"></i>
|
<i class="fas fa-angle-up"></i>
|
||||||
</a>
|
</button>
|
||||||
|
|
||||||
{% if site.pwa.enabled %}
|
{% if site.pwa.enabled %}
|
||||||
<div
|
<div
|
||||||
|
|
Loading…
Reference in a new issue