Skip to content

Commit

Permalink
Jump to the anchor position smoothly
Browse files Browse the repository at this point in the history
  • Loading branch information
cotes2020 committed Dec 25, 2020
1 parent fa310d3 commit dfba411
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
3 changes: 2 additions & 1 deletion assets/css/_addon/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ html[mode=dark] {
}
}

html, body {
:root {
font-size: 16px;
scroll-behavior: smooth;
}

body {
Expand Down
9 changes: 3 additions & 6 deletions assets/js/_commons/back-to-top.js
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -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;
});
});

0 comments on commit dfba411

Please sign in to comment.