-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathscript.js
45 lines (39 loc) · 1.34 KB
/
script.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
34
35
36
37
38
39
40
41
42
43
44
45
// Select the scroll button
const scrollButton = document.getElementById("scrollButton");
// Show/hide scroll button with smooth animation
window.addEventListener("scroll", () => {
if (window.scrollY > 100) {
scrollButton.classList.add("show");
scrollButton.style.animation = "fadeInButton 0.5s ease-out forwards";
} else {
scrollButton.style.animation = "fadeOutButton 0.5s ease-out forwards";
setTimeout(() => {
scrollButton.classList.remove("show");
}, 500);
}
});
// Smooth scroll with easing
scrollButton.addEventListener("click", () => {
// Add active state
scrollButton.classList.add("active");
// Smooth scroll with cubic-bezier easing
const scrollToTop = () => {
const currentPosition = window.pageYOffset;
if (currentPosition > 0) {
window.requestAnimationFrame(scrollToTop);
window.scrollTo(0, currentPosition - currentPosition/8);
} else {
scrollButton.classList.remove("active");
}
};
scrollToTop();
});
// Add hover effect
scrollButton.addEventListener("mouseover", () => {
scrollButton.style.transform = "scale(1.15) translateY(-3px)";
scrollButton.style.boxShadow = "0 6px 20px rgba(0,0,0,0.4)";
});
scrollButton.addEventListener("mouseout", () => {
scrollButton.style.transform = "scale(1)";
scrollButton.style.boxShadow = "0 4px 15px rgba(0,0,0,0.3)";
});