Programming/JavaScript

[JavaScript] ํŠน์ • ์š”์†Œ element ์œ„์น˜๋กœ ์Šคํฌ๋กค ์ด๋™ํ•˜๋Š” ๋ฐฉ๋ฒ• scrollIntoView

yuri lee 2023. 6. 3. 15:58
๋ฐ˜์‘ํ˜•

Intro

์•ˆ๋…•ํ•˜์„ธ์š”. ๋ชจ๋ฐ”์ผ ๋„ค๋น„๊ฒŒ์ด์…˜ ๋ฉ”๋‰ด์—์„œ ์Šคํฌ๋กค ์ด๋™์„ ํ‘œํ˜„ํ•ด์•ผ ํ–ˆ์Šต๋‹ˆ๋‹ค. ์—ฌ๋Ÿฌ ๋ฐฉ๋ฒ•์ด ์žˆ๊ฒ ์ง€๋งŒ ์ €๋Š” ํŠน์ • ์š”์†Œ ์œ„์น˜๋กœ ์Šคํฌ๋กค ์ด๋™ํ•  ์ˆ˜ ์žˆ๋Š” scrollIntoView ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ–ˆ์Šต๋‹ˆ๋‹ค.

 

Syntax

scrollIntoView()
scrollIntoView(alignToTop)
scrollIntoView(scrollIntoViewOptions)

alignToTop

- true : aligned to the top ์ƒ๋‹จ ๊ธฐ์ค€ ์Šคํฌ๋กค ์ด๋™ |  scrollIntoViewOptions: {block: "start", inline: "nearest"}

- false : aligned to the bottom ํ•˜๋‹จ ๊ธฐ์ค€ ์Šคํฌ๋กค ์ด๋™ |  scrollIntoViewOptions: {block: "end", inline: "nearest"}

 

scrollIntoViewOptions

- behavior : ์—๋‹ˆ๋ฉ”์ด์…˜ | smooth, instant, auto 

- block : ์ˆ˜์ง ์ •๋ ฌ | start, center, end, or nearest. Defaults to start

- inlihne : ์ˆ˜ํ‰ ์ •๋ ฌ | start, center, end, or nearest. Defaults to nearest

 

 


https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView

๋ฐ˜์‘ํ˜•