8000 carousel update · codewithdev/codewithdev-vercel@8dd9970 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8dd9970

Browse files
committed
carousel update
1 parent 07892f6 commit 8dd9970

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

pages/about.tsx

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useTheme } from 'next-themes';
44
import { FaGithub, FaLinkedin, FaGlobe } from 'react-icons/fa';
55
import { FaXTwitter as FaXTwitter } from 'react-icons/fa6';
66
import { LuExternalLink } from "react-icons/lu";
7-
import { motion } from 'framer-motion';
7+
import { motion, AnimatePresence, PanInfo } from 'framer-motion';
88
import { useState, useEffect } from 'react';
99
import { BsArrowLeftCircle, BsArrowRightCircle } from 'react-icons/bs';
1010

@@ -106,6 +106,21 @@ export default function About() {
106106
});
107107
};
108108

109+
const swipeConfidenceThreshold = 10000;
110+
const swipePower = (offset: number, velocity: number) => {
111+
return Math.abs(offset) * velocity;
112+
};
113+
114+
const handleDragEnd = (e: any, { offset, velocity }: PanInfo) => {
115+
const swipe = swipePower(offset.x, velocity.x);
116+
117+
if (swipe < -swipeConfidenceThreshold) {
118+
paginate(1);
119+
} else if (swipe > swipeConfidenceThreshold) {
120+
paginate(-1);
121+
}
122+
};
123+
109124
return (
110125
<Container title="About – Dev">
111126
<div className="flex flex-col justify-center items-start max-w-xl mx-auto mb-16 w-full">
@@ -173,7 +188,11 @@ export default function About() {
173188
transition={{
174189
duration: 0.5
175190
}}
176-
className="absolute w-[180px] md:w-[240px]"
191+
drag="x"
192+
dragConstraints={{ left: 0, right: 0 }}
193+
dragElastic={1}
194+
onDragEnd={handleDragEnd}
195+
className="absolute w-[90vw] sm:w-full max-w-[300px]"
177196
>
178197
<div className={`${timeline[index].bgColor} p-3 md:p-4 rounded-lg shadow-sm dark:border dark:border-gray-700 transition-colors duration-300 relative overflow-hidden`}>
179198
<div className="flex flex-col items-start space-y-0.5">

0 commit comments

Comments
 (0)
0