스크롤에 따라 텍스트가 움직이는 효과를 주면서 스크롤 강도에 따라 텍스트의 기울기가 변화하는 효과를 구현하고 싶었다.
스크롤을 할 만큼의 높이가 필요하다.
<section className="h-[500vh]"></section>
텍스트가 부모 요소의 영역을 넘어가더라도 한 줄로 위치해있어야 한다.
<div className="overflow-hidden h-screen sticky top-0">
<p className="origin-bottom-left whitespace-nowrap uppercase">
{`Nothing in this world can take the place of persistence. Talent will not; nothing is more common than unsuccessful men with talent. Genius
will not; unrewarded genius is almost a proverb. Education will not; the world is full of educated derelicts. Persistence and determination
alone are omnipotent. The slogan 'Press On!' has solved and always will solve the problems of the human race.
`}
</p>
</div>
['start start', 'end start'] : 요소의 시작부분이 뷰포트의 시작부분과 일치할 때, 요소의 끝 부분이 뷰포트의 시작 부분과 일치할 때를 의미한다.
<div className="overflow-hidden h-screen sticky top-0">
<p className="h-screen origin-bottom-left whitespace-nowrap uppercase">
{`Nothing in this world can take the place of persistence. Talent will not; nothing is more common than unsuccessful men with talent. Genius
will not; unrewarded genius is almost a proverb. Education will not; the world is full of educated derelicts. Persistence and determination
alone are omnipotent. The slogan 'Press On!' has solved and always will solve the problems of the human race.
`}
</p>
</div>
</section>
scrollYProgress 값의 변화 속도를 계산해야한다. 👉🏻 useVelocity
useVelocity는 주어진 valeu의 변화율을 추적하고 그에 따라 속도를 계산한다.
const velocityValue = useVelocity(value)
입력 값: value는 보통 motion 값(예: scrollYProgress)이며, useVelocity는 해당 값이 얼마나 빨리 변하고 있는지를 측정한다.
출력 값: useVelocity는 value의 변화 속도를 나타내는 값(속도 값)을 반환한다. 이 값을 사용해 스크롤 속도에 따른 애니메이션 효과를 만들 수 있다.
✅스크롤 속도에 따라 기울기, 크기 변화, 색상 변경 등의 효과를 줄 때 활용할 수 있다.
<motion.p
style={{ skewX, x }}
className="h-screen origin-bottom-left whitespace-nowrap uppercase">
{`Nothing in this world can take the place of persistence. Talent will not; nothing is more common than unsuccessful men with talent. Genius
will not; unrewarded genius is almost a proverb. Education will not; the world is full of educated derelicts. Persistence and determination
alone are omnipotent. The slogan 'Press On!' has solved and always will solve the problems of the human race.
`}
</motion.p>