-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
47 lines (40 loc) · 1.49 KB
/
Copy pathscript.js
File metadata and controls
47 lines (40 loc) · 1.49 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
document.addEventListener("DOMContentLoaded", function () {
var scrollButton = document.getElementById("scroll-to-top");
window.onscroll = function () {
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
scrollButton.style.display = "block";
} else {
scrollButton.style.display = "none";
}
};
window.scrollToTop = function () {
scrollTo(document.documentElement, 0, 500); // Scroll to the top with a duration of 500 milliseconds
};
function scrollTo(element, to, duration) {
var start = element.scrollTop,
change = to - start,
currentTime = 0,
increment = 20;
var animateScroll = function () {
currentTime += increment;
var val = Math.easeInOutQuad(currentTime, start, change, duration);
element.scrollTop = val;
if (currentTime < duration) {
requestAnimationFrame(animateScroll);
}
};
animateScroll();
}
// Easing function for smooth scroll animation
Math.easeInOutQuad = function (t, b, c, d) {
t /= d / 2;
if (t < 1) return c / 2 * t * t + b;
t--;
return -c / 2 * (t * (t - 2) - 1) + b;
};
});
// Toggle share icons visibility
function toggleShareIcons() {
var shareIcons = document.getElementById("floating-share-icons");
shareIcons.classList.toggle("show");
}