Skip to content

Commit

Permalink
test (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
omarghandour authored Nov 6, 2024
2 parents 43e3b12 + b352dcd commit dcfacbf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 33 deletions.
44 changes: 12 additions & 32 deletions app/components/ScrollBySection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,22 @@ const ScrollBySection: React.FC = () => {
const isScrolling = useRef<boolean>(false);
const touchStart = useRef<number>(0);
const SWIPE_THRESHOLD = 40;
const SCROLL_DURATION = 800; // Duration of the scroll animation in ms

const smoothScrollTo = (targetY: number) => {
const startY = window.scrollY;
const distance = targetY - startY;
let startTime: number | null = null;

const animateScroll = (currentTime: number) => {
if (startTime === null) startTime = currentTime;
const timeElapsed = currentTime - startTime;
const progress = Math.min(timeElapsed / SCROLL_DURATION, 1);

// Ease-in-out effect
const easeInOut =
progress < 0.5
? 2 * progress * progress
: -1 + (4 - 2 * progress) * progress;

window.scrollTo(0, startY + distance * easeInOut);

if (progress < 1) {
requestAnimationFrame(animateScroll);
} else {
isScrolling.current = false; // Reset scrolling lock
}
};

requestAnimationFrame(animateScroll);
};
const SCROLL_DURATION = 800; // Adjust duration if needed

const scrollToSection = (index: number) => {
if (isScrolling.current || index === activeIndex) return;

isScrolling.current = true;
setActiveIndex(index);

const targetSection = sectionRefs.current[index];
if (targetSection) {
isScrolling.current = true;
smoothScrollTo(targetSection.offsetTop);
setActiveIndex(index);
// Scroll to the target section with smooth behavior
targetSection.scrollIntoView({ behavior: "smooth" });

setTimeout(() => {
isScrolling.current = false;
}, SCROLL_DURATION);
}
};

Expand Down
5 changes: 4 additions & 1 deletion app/globals.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

html,
body {
scroll-behavior: smooth !important;
}
body {
font-family: Arial, Helvetica, sans-serif;
}
Expand Down

1 comment on commit dcfacbf

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for blackwaves ready!

✅ Preview
https://blackwaves-8vjnz28q7-omarkhaled9913gmailcoms-projects.vercel.app

Built with commit dcfacbf.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.