Jump to the anchor position smoothly

This commit is contained in:
Cotes Chung 2020-12-24 22:51:08 +08:00
parent fa310d3190
commit dfba411d61
2 changed files with 5 additions and 7 deletions

View File

@ -46,8 +46,9 @@ html[mode=dark] {
}
}
html, body {
:root {
font-size: 16px;
scroll-behavior: smooth;
}
body {

View File

@ -1,9 +1,8 @@
/*
Reference: https://bootsnipp.com/snippets/featured/link-to-top-page
*/
$(function() {
$(window).scroll(function() {
$(window).scroll(() => {
if ($(this).scrollTop() > 50 &&
$("#sidebar-trigger").css("display") === "none") {
$("#back-to-top").fadeIn();
@ -12,10 +11,8 @@ $(function() {
}
});
$("#back-to-top").click(function() {
$("body,html").animate({
scrollTop: 0
}, 800);
$("#back-to-top").click(() => {
$("body,html").scrollTop(0);
return false;
});
});