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

λ°˜μ‘ν˜•