Troubleshooting background image

This commit is contained in:
jme9
2024-12-11 11:00:32 -08:00
parent 01bd231181
commit 1dd2e759d6
2 changed files with 29 additions and 3 deletions
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 56 KiB

After

Width:  |  Height:  |  Size: 56 KiB

+29 -3
View File
@@ -3,9 +3,35 @@ document.addEventListener("DOMContentLoaded", () => {
document.querySelectorAll(".nav-link").forEach((anchor) => { document.querySelectorAll(".nav-link").forEach((anchor) => {
anchor.addEventListener("click", function (e) { anchor.addEventListener("click", function (e) {
e.preventDefault(); e.preventDefault();
document.querySelector(this.getAttribute("href")).scrollIntoView({
behavior: "smooth", const target = document.querySelector(this.getAttribute("href"));
}); if (!target) return;
const targetPosition =
target.getBoundingClientRect().top + window.scrollY;
const startPosition = window.scrollY;
const distance = targetPosition - startPosition;
const duration = 1000;
let startTime = null;
function easeOutCubic(t) {
// Custom easing function for gradual slowdown
return 1 - Math.pow(1 - t, 3);
}
function scrollAnimation(currentTime) {
if (!startTime) startTime = currentTime;
const timeElapsed = currentTime - startTime;
const progress = Math.min(timeElapsed / duration, 1); // Ensure progress doesn't exceed 1
const easeProgress = easeOutCubic(progress);
window.scrollTo(0, startPosition + distance * easeProgress);
if (progress < 1) {
requestAnimationFrame(scrollAnimation);
}
}
requestAnimationFrame(scrollAnimation);
}); });
}); });