๐ฏ ๋ชฉํ
- y์ถ ์คํฌ๋กค์ด ๊ฐ์ง๋๋ฉด ์ด๋ฏธ์ง ์๋ ์ฌ๋ผ์ด๋ ๋ฐ ํ ์คํธ ๋ ธ์ถ ํจ๊ณผ
html ๊ตฌ์กฐ (jsx)
<article>
<div>
<div>
<img
src={VisionPro_item02}
alt='VisionPro'
></img>
</div>
<div></div> //๋ผ์ธ ์
<div>
<p>Head bands</p>
<p>The Solo Knit Band provides cushioning, breathability, <br />and stretch,and a Fit Dial lets you adjust Apple Vision Pro<br />precisely to your head. </p>
</div>
<div></div> //๋ผ์ธ ์
<div>
<p>Power</p>
<p>The external battery supports up to 2 hours of <br /> general use and up to 2.5 hours of video playback. </p>
</div>
</div>
</article >
๐ค ์๋ฐ์คํฌ๋ฆฝํธ์์ ์คํฌ๋กค ๋์์ ๊ฐ์งํด์ฃผ๋ ์์ฑ
window.pageYOffset , Window.scrollY : ์คํฌ๋กค์ ์์ง ๊ฐ์ ํฝ์ ๋จ์๋ก ๋ฐํ
์ฒ์ ํ์ด์ง๊ฐ ๋ ๋๋ง๋๊ณ ์คํฌ๋กค ๋์์ด ์์ผ๋ฉด ๋ํดํธ๊ฐ์ผ๋ก 0์ ๋ฐํํ๋ค.
MDN์์๋ ๋ธ๋ผ์ฐ์ ๊ฐ ํธํ์ฑ์ ์ํด window.pageYOffset ์ฌ์ฉ์ ๊ถ์ฅํ๋ค.
์คํฌ๋กค ์ถ์ ๋ฐ ๊ด๋ฆฌ ๋ก์ง ์์ฑ
์คํฌ๋กค ์์น๋ฅผ ๊ฐ์งํ๊ณ ํด๋น ์์น๋ฅผ ์ํ๋ก ๊ด๋ฆฌํด์ผํ๋ค.
// ํ์ฌ ์คํฌ๋กค ์์น๊ฐ ์ ์ฅ
const [scrollPosition, setScrollPosition] = useState(0);
useEffect(() => {
// ํ์ฌ ์คํฌ๋กค ์์น๊ฐ ์ํ๊ฐ ์
๋ฐ์ดํธ ํจ์
const handleScroll = () => {
const position = window.pageYOffset;
setScrollPosition(position);
}
// ์คํฌ๋กค ์ด๋ฒคํธ ๋ฆฌ์ค๋ ๋ฑ๋ก
window.addEventListener('scroll', handleScroll);
// ์ปดํฌ๋ํธ ์ธ๋ง์ดํธ ์ ์ด๋ฒคํธ ๋ฆฌ์ค๋ ํด์
return () => {
window.removeEventListener('scroll', handleScroll);
}
}, [])
1. ํ์ฌ ์คํฌ๋กค ์์น๊ฐ์ ์ ์ฅํ๋ ์ํ๋ฅผ ์ ์ธ.
ํด๋นํ์ด์ง์์ ์คํฌ๋กค ๊ฐ์ ๊ณ์ ๋ณํ๊ธฐ ๋๋ฌธ์ ๋ณ์๊ฐ ์๋ ์ํ์ ์ ์ฅํจ.
2. ํ์ฌ ์คํฌ๋กค ์์น๊ฐ์ ์ํ์ ์ ๋ฐ์ดํธ ํ๋ ํจ์.
3. ์คํฌ๋กค ์ด๋ฒคํธ ๋ฆฌ์ค๋ ๋ฑ๋ก
4. ์ปดํฌ๋ํธ ์ธ๋ง์ดํธ ์ ์ด๋ฒคํธ ๋ฆฌ์ค๋ ํด์
5. ์ปดํฌ๋ํธ๊ฐ ์ฒ์ ๋ง์ดํธ๋ ๋๋ง ์คํ๋จ