-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
33 lines (29 loc) · 780 Bytes
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
$(document).ready(function () {
// Initial state of the back-to-top button
$(".back-to-top").hide();
// Function to check scroll position and toggle the button
function toggleBackToTopButton() {
var scrollPosition = $(window).scrollTop();
var articleSectionOffset = $("#article").offset().top;
if (scrollPosition > articleSectionOffset) {
$(".back-to-top").fadeIn("slow");
} else {
$(".back-to-top").fadeOut("slow");
}
}
// Event listener for scroll
$(window).scroll(function () {
toggleBackToTopButton();
});
// Event listener for button click
$(".back-to-top").click(function () {
$("html, body").animate(
{
scrollTop: 0,
},
1500,
"easeInOutExpo"
);
return false;
});
});