-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SP2] 메인 상단 Introduce QA #292
Changes from 4 commits
86a9aae
00d4080
e33a678
62c8892
42b66f0
6b4df22
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,40 @@ | ||
import { useScroll, useTransform } from 'framer-motion'; | ||
import { useRef } from 'react'; | ||
import MotionTitle from './MotionTitle'; | ||
import { useEffect, useRef, useState } from 'react'; | ||
import { useIsMobile } from '@src/hooks/useDevice'; | ||
import * as S from './style'; | ||
|
||
export default function Introduce() { | ||
const isMobileSize = useIsMobile('768px'); | ||
const contentRef = useRef<HTMLElement>(null); | ||
const { scrollYProgress } = useScroll({ | ||
target: contentRef, | ||
offset: ['end center', 'start start'], | ||
offset: ['end center', 'start'], | ||
}); | ||
|
||
const scaleValue = useTransform(scrollYProgress, [1, 0.4], [0.9, 1]); | ||
const content = '전국 최대 규모의 대학생 IT 연합 동아리, SOPT를 소개합니다.'; | ||
|
||
const [style, setStyle] = useState<{ opacity?: number; clipPath?: string }>(); | ||
const scrollValue = useTransform(scrollYProgress, [1, 0.4], ['100%', '0%']); | ||
|
||
useEffect(() => { | ||
const unsubscribe = scrollValue.on('change', (value) => { | ||
const percentValue = Number(value.split('%')[0]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. value의 타입은 string인가용? 다른 방법으로 얻어올 방법은 없나요!?? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 코드에서 value 타입은 string입니다!! |
||
const newStyle = isMobileSize | ||
? { opacity: (100 - percentValue) / 100 } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 정말 사소한 것이긴 한데 G한테 물어보았어용
따라서, 특별한 상황이 아니라면 "1 - value/100"을 사용하는 것이 효율적인 선택이 될 수 있습니다. 이는 코드의 간결함과 가독성 측면에서 특히 웹 개발 환경에 적합합니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 식을 전개하면 GPT가 알려준대로 식이 나오겠네요! 전개하는게 더 깔끔한 것 같습니다!! |
||
: { clipPath: `inset(0% ${percentValue}% 0% 0%)`, opacity: 1 }; | ||
setStyle(newStyle); | ||
}); | ||
|
||
return () => { | ||
unsubscribe(); | ||
}; | ||
}, [scrollValue, isMobileSize]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ㅜㅜ폴더를 나눴다가 문제가 생긴 거였군요 .. |
||
return ( | ||
<S.Background ref={contentRef}> | ||
<S.Wrapper> | ||
<S.TextContainer style={{ scale: scaleValue }}> | ||
<MotionTitle contentRef={contentRef} content={content} /> | ||
<S.MotionTitle style={style} data-text={content} /> | ||
<S.BackgroundTitle>{content}</S.BackgroundTitle> | ||
</S.TextContainer> | ||
</S.Wrapper> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ import { motion } from 'framer-motion'; | |
|
||
export const Background = styled.section` | ||
display: flex; | ||
max-width: 1920px; | ||
height: 200vh; | ||
justify-content: center; | ||
align-items: flex-start; | ||
|
@@ -63,6 +62,21 @@ export const TextContainer = styled(motion.span)` | |
} | ||
`; | ||
|
||
export const MotionTitle = styled(motion.span)` | ||
position: absolute; | ||
left: 0; | ||
opacity: 0; | ||
|
||
:before { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 가능하면 가상 요소는 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 감사합니다!! |
||
content: attr(data-text); | ||
display: inline-block; | ||
background: linear-gradient(93deg, #c9d8dd 78.65%, #fff 128.82%, #c9d8dd 137.19%); | ||
background-clip: text; | ||
-webkit-background-clip: text; | ||
-webkit-text-fill-color: transparent; | ||
} | ||
`; | ||
|
||
export const BackgroundTitle = styled.span` | ||
background: linear-gradient(93deg, #c9d8dd -34.77%, #fff -14.77%, #636770 6.12%); | ||
background-clip: text; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
여기서
%
를 안 붙이면, 아래에서도%
를 통한 파싱을 하지 않아도 되는 건가요?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
처음에는 clipPath 속성에서 %값을 사용해 %를 붙인 코드로 작성했는데 opacity와 clipPath 스타일을 합쳐서 사용하는 경우에는 %를 지우면 되겠군요..! 아래 문제도 해결할 수 있을 것 같습니다!