Skip to content
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

Merged
merged 6 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 0 additions & 37 deletions src/views/MainPage/components/Introduce/MotionTitle/index.tsx

This file was deleted.

16 changes: 0 additions & 16 deletions src/views/MainPage/components/Introduce/MotionTitle/style.ts

This file was deleted.

25 changes: 21 additions & 4 deletions src/views/MainPage/components/Introduce/index.tsx
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%']);
Copy link
Member

Choose a reason for hiding this comment

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

여기서 %를 안 붙이면, 아래에서도 %를 통한 파싱을 하지 않아도 되는 건가요?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

처음에는 clipPath 속성에서 %값을 사용해 %를 붙인 코드로 작성했는데 opacity와 clipPath 스타일을 합쳐서 사용하는 경우에는 %를 지우면 되겠군요..! 아래 문제도 해결할 수 있을 것 같습니다!


useEffect(() => {
const unsubscribe = scrollValue.on('change', (value) => {
const percentValue = Number(value.split('%')[0]);
Copy link
Member

@SeojinSeojin SeojinSeojin Nov 24, 2023

Choose a reason for hiding this comment

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

value의 타입은 string인가용? 다른 방법으로 얻어올 방법은 없나요!??
%로 파싱하고 Number로 타입 바꾸지 않고 가져오는 방법은 없는 것인가요?!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

코드에서 value 타입은 string입니다!!

const newStyle = isMobileSize
? { opacity: (100 - percentValue) / 100 }
Copy link
Member

Choose a reason for hiding this comment

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

정말 사소한 것이긴 한데 1 - percentValue/100 하면 계산하는 숫자가 더 작아져서 좋을 것 같다는 생각이 듭니다!

G한테 물어보았어용

  1. 실행 속도: 현대의 컴파일러와 인터프리터는 최적화가 매우 잘 되어 있어, 이 두 식 사이에 실행 속도 차이는 거의 없거나 미미할 것입니다. 웹 환경에서는 JavaScript 엔진이 이러한 최적화를 처리합니다.
  2. 가독성: "1 - value/100"은 더 단순하고 직관적입니다. 이 식은 "원래 값에서 어떤 비율을 뺀다"는 개념을 직접적으로 표현합니다. 반면, "(100 - value)/100"은 두 단계의 계산을 거치는 것처럼 보일 수 있습니다.
  3. 오류 가능성: 더 간단한 식은 일반적으로 오류 발생 가능성이 낮습니다. "1 - value/100"은 단순화된 형태로, 잘못된 계산이나 오류 발생 가능성이 더 낮을 수 있습니다.

따라서, 특별한 상황이 아니라면 "1 - value/100"을 사용하는 것이 효율적인 선택이 될 수 있습니다. 이는 코드의 간결함과 가독성 측면에서 특히 웹 개발 환경에 적합합니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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]);
Copy link
Member

Choose a reason for hiding this comment

The 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>
Expand Down
16 changes: 15 additions & 1 deletion src/views/MainPage/components/Introduce/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -63,6 +62,21 @@ export const TextContainer = styled(motion.span)`
}
`;

export const MotionTitle = styled(motion.span)`
position: absolute;
left: 0;
opacity: 0;

:before {
Copy link
Member

Choose a reason for hiding this comment

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

가능하면 가상 요소는 ::로 작성하는 게 좋을 것 같습니다!! [참고]

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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;
Expand Down
Loading