web/_javascript/modules/components/back-to-top.js
Cotes Chung b69d3d7edd
refactor(build): modularize JS code
- replace gulp with rollup
- remove JS output from repo
2023-03-15 21:51:37 +08:00

26 lines
493 B
JavaScript

/**
* Reference: https://bootsnipp.com/snippets/featured/link-to-top-page
*/
export function back2top() {
$(window).on('scroll', () => {
if (
$(window).scrollTop() > 50 &&
$('#sidebar-trigger').css('display') === 'none'
) {
$('#back-to-top').fadeIn();
} else {
$('#back-to-top').fadeOut();
}
});
$('#back-to-top').on('click', () => {
$('body,html').animate(
{
scrollTop: 0
},
800
);
return false;
});
}