f6bf6d0864
The current "back to top" button is built by `<a>` tag, it would be more appropriate to replace it with the `<button>` tag.
20 lines
370 B
JavaScript
20 lines
370 B
JavaScript
/**
|
|
* Reference: https://bootsnipp.com/snippets/featured/link-to-top-page
|
|
*/
|
|
|
|
export function back2top() {
|
|
const $window = $(window);
|
|
const $btn = $('#back-to-top');
|
|
|
|
$window.on('scroll', () => {
|
|
if ($window.scrollTop() > 50) {
|
|
$btn.fadeIn();
|
|
} else {
|
|
$btn.fadeOut();
|
|
}
|
|
});
|
|
|
|
$btn.on('click', () => {
|
|
$window.scrollTop(0);
|
|
});
|
|
}
|