Skip to content

Commit cc17dc2

Browse files
committed
save
1 parent f417ced commit cc17dc2

File tree

7 files changed

+68
-61
lines changed

7 files changed

+68
-61
lines changed

src/components/About.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ const About: any = () => {
55
const { elementRef, inView } = useIntersectionObserver({
66
threshold: 0.8,
77
rootMargin: '0px',
8+
mobileThreshold: 0.5,
9+
mobileRootMargin: '-50px',
810
});
911

1012
return (

src/components/Education.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ const Education: any = () => {
88
const { elementRef, inView } = useIntersectionObserver({
99
threshold: 0.8,
1010
rootMargin: '0px',
11+
mobileThreshold: 0.5,
12+
mobileRootMargin: '-50px',
1113
});
1214

1315
return (

src/components/ExperienceWrapper.tsx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,33 @@ const ExperienceWrapper = ({
2323
}: ExperienceProps) => {
2424
const { elementRef, inView } = useIntersectionObserver({
2525
threshold: 0.8,
26-
rootMargin: '0px',
26+
rootMargin: '-150px',
27+
mobileThreshold: 0.5,
28+
mobileRootMargin: '-50px',
2729
});
2830

29-
console.log('🔥 : inView =>', inView);
30-
3131
return (
3232
<div
3333
ref={elementRef}
34-
className={cn(
35-
'p-4 mb-12 hover:shadow-border group hover:bg-background',
36-
inView && 'md:bg-transparent md:shadow-none bg-background shadow-border'
37-
)}
34+
className={cn('p-4 mb-12 group', inView && 'bg-background shadow-border')}
3835
>
3936
<div className="flex gap-4 mb-4">
4037
<Image src={imageSrc} alt={title} className="w-16 h-16 rounded" />
4138
<div>
4239
<Link
4340
href={link}
4441
className={cn(
45-
'text-xl font-semibold w-fit md:whitespace-nowrap group-hover:text-secondary underline-animation',
46-
inView && 'text-secondary !text-red-300'
42+
'text-white flex items-center gap-1 text-xl font-semibold whitespace-nowrap underline-animation',
43+
inView && 'text-secondary'
4744
)}
4845
>
4946
{title}
50-
<BsLink45Deg className="absolute top-[6px] right-[-20px] text-secondary link-icon" />
47+
<BsLink45Deg
48+
className={cn(
49+
'opacity-0 text-secondary transition-all duration-500 ease-out',
50+
inView && 'opacity-100'
51+
)}
52+
/>
5153
</Link>
5254
<h2>{role}</h2>
5355
<h5 className="text-xs">{date}</h5>

src/components/ProjectWrapper.tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ const Project = ({
3131
const [open, setOpen] = useState(false);
3232
const { elementRef, inView } = useIntersectionObserver({
3333
threshold: 0.8,
34-
rootMargin: '0px',
34+
rootMargin: '-150px',
35+
mobileThreshold: 0.5,
36+
mobileRootMargin: '-50px',
3537
});
3638
const imageSrc = imageCount
3739
? `/images/projects/${gallerySrc}/${gallerySrc}01.jpg`
@@ -42,16 +44,16 @@ const Project = ({
4244
<div
4345
ref={elementRef}
4446
className={cn(
45-
'p-4 mb-12 lg:mb-24 hover:shadow-border group hover:bg-background',
46-
inView && 'bg-background shadow-border md:bg-transparent md:shadow-none'
47+
'p-4 mb-12 lg:mb-24 group',
48+
inView && 'bg-background shadow-border'
4749
)}
4850
>
49-
<div className="flex w-full gap-6 max-md:flex-col">
51+
<div className="flex w-full gap-6 max-md:flex-col group">
5052
<div
5153
onClick={() => {
5254
setOpen(true);
5355
}}
54-
className="h-full overflow-hidden rounded-lg cursor-pointer md:w-2/5 shadow-border"
56+
className="h-full overflow-hidden rounded-lg cursor-pointer md:w-2/5 group-hover:shadow-border"
5557
>
5658
<Image
5759
src={imageSrc}
@@ -65,16 +67,15 @@ const Project = ({
6567
<Link
6668
href={link}
6769
className={cn(
68-
'mb-2 text-xl font-semibold whitespace-nowrap group-hover:text-secondary underline-animation',
70+
'text-white flex items-center gap-1 mb-2 text-xl font-semibold whitespace-nowrap underline-animation',
6971
inView && 'text-secondary'
7072
)}
7173
>
7274
{title}
7375
<BsLink45Deg
7476
className={cn(
75-
'absolute top-[6px] right-[-20px] text-secondary link-icon group-hover:visible group-hover:underline-animation',
76-
inView &&
77-
'text-secondary opacity-100 visible underline-animation'
77+
'opacity-0 text-secondary transition-all duration-500 ease-out',
78+
inView && 'opacity-100'
7879
)}
7980
/>
8081
</Link>

src/styles/animations.css

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
display: inline-block;
3131
width: min-content !important;
3232
position: relative;
33-
transition: color 0.5s ease-in-out;
33+
transition: all 0.5s ease-in-out;
3434
color: var(--color-secondary);
3535
}
3636

@@ -44,41 +44,14 @@
4444
background-color: var(--color-secondary);
4545
transform: scaleX(0);
4646
transform-origin: bottom right;
47-
transition: transform 0.3s ease-out;
47+
transition: transform 0.5s ease-out;
4848
}
4949

5050
.underline-animation:hover:after {
5151
transform: scaleX(1);
5252
transform-origin: bottom left;
5353
}
5454

55-
@media (max-width: 768px) {
56-
.underline-animation:after {
57-
transform: scaleX(1);
58-
transform-origin: bottom left;
59-
}
60-
}
61-
62-
.link-icon {
63-
visibility: hidden;
64-
opacity: 0;
65-
transition: opacity 0.5s ease-in-out;
66-
}
67-
68-
/* @media (min-width: 1024px) {
69-
.group:hover .link-icon {
70-
visibility: visible;
71-
opacity: 1;
72-
}
73-
}
74-
75-
@media (max-width: 1023px) {
76-
.in-view .link-icon {
77-
visibility: visible;
78-
opacity: 1;
79-
}
80-
} */
81-
8255
/* ------ Blur Animation ----- */
8356

8457
.blur-animation {

src/styles/globals.css

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,10 @@ h5 {
5757
color: var(--color-primary);
5858
}
5959

60-
.shadow-border {
61-
border-radius: 8px;
62-
transition: all 0.5s ease-in-out !important;
63-
box-shadow: 0px 0px 12px 0px var(--color-secondary) !important;
64-
&:hover {
65-
box-shadow: 0px 0px 12px 0px var(--color-secondary) !important;
60+
@layer components {
61+
.shadow-border {
62+
@apply transition-all duration-500 ease-in-out rounded-lg;
63+
box-shadow: 0px 0px 12px 0px var(--color-secondary);
6664
}
6765
}
6866

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,47 @@
11
import { useEffect, useRef, useState } from 'react';
22

3-
export const useIntersectionObserver = (options = {}) => {
3+
interface IntersectionOptions {
4+
threshold?: number;
5+
rootMargin?: string;
6+
mobileThreshold?: number;
7+
mobileRootMargin?: string;
8+
}
9+
10+
export const useIntersectionObserver = (options: IntersectionOptions = {}) => {
411
const elementRef = useRef<HTMLDivElement>(null);
512
const [inView, setInView] = useState(false);
13+
const [isMobile, setIsMobile] = useState(false);
14+
15+
useEffect(() => {
16+
const checkMobile = () => {
17+
setIsMobile(window.innerWidth < 768); // 768px is typical mobile breakpoint
18+
};
19+
20+
checkMobile();
21+
window.addEventListener('resize', checkMobile);
22+
23+
return () => window.removeEventListener('resize', checkMobile);
24+
}, []);
625

726
useEffect(() => {
827
const element = elementRef.current;
928
if (!element) return;
1029

11-
const observer = new IntersectionObserver((entries) => {
12-
entries.forEach((entry) => {
13-
setInView(entry.isIntersecting);
14-
});
15-
}, options);
30+
const observer = new IntersectionObserver(
31+
(entries) => {
32+
entries.forEach((entry) => {
33+
setInView(entry.isIntersecting);
34+
});
35+
},
36+
{
37+
threshold: isMobile
38+
? options.mobileThreshold ?? options.threshold
39+
: options.threshold,
40+
rootMargin: isMobile
41+
? options.mobileRootMargin ?? options.rootMargin
42+
: options.rootMargin,
43+
}
44+
);
1645

1746
observer.observe(element);
1847

@@ -21,7 +50,7 @@ export const useIntersectionObserver = (options = {}) => {
2150
observer.unobserve(element);
2251
}
2352
};
24-
}, [options]);
53+
}, [options, isMobile]);
2554

2655
return { elementRef, inView };
2756
};

0 commit comments

Comments
 (0)