useScroll
Element scroll progress
import "./styles.css";
import { useRef } from "react";
import { motion, useScroll } from "framer-motion";
export default function App() {
const ref = useRef(null); // 스크롤을 감지할 요소에 적용
const { scrollXProgress } = useScroll({ container: ref });
return (
<>
<svg id="progress" width="100" height="100" viewBox="0 0 100 100">
<circle cx="50" cy="50" r="30" pathLength="1" className="bg" />
<motion.circle
cx="50"
cy="50"
r="30"
pathLength="1"
className="indicator"
style={{ pathLength: scrollXProgress }} // X스크롤의 진행률을 svg 요소에 적용
/>
</svg>
<ul ref={ref}> // ➡️ 스크롤바가 생기는 요소, X축으로 스크롤바 생김
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</>
);
}
Parallax
Image Component
useParallax
Scroll velocity
Last updated