-
Notifications
You must be signed in to change notification settings - Fork 845
Part2 3.6 Scrolling λ²μ #1554
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking βSign up for GitHubβ, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -1,12 +1,12 @@ | ||||||||||
# Scrolling | ||||||||||
# μ€ν¬λ‘€ | ||||||||||
|
||||||||||
The `scroll` event allows reacting to a page or element scrolling. There are quite a few good things we can do here. | ||||||||||
`Scroll` μ΄λ²€νΈλ νμ΄μ§ λλ μμ μ€ν¬λ‘€μ μλ΅ν μ μμ΅λλ€. μ΄ νμ΄μ§μμ ν μ μλ μ’μ μμκ° κ½€ λ§μ΄ μμ΅λλ€. | ||||||||||
|
||||||||||
For instance: | ||||||||||
- Show/hide additional controls or information depending on where in the document the user is. | ||||||||||
- Load more data when the user scrolls down till the end of the page. | ||||||||||
μμ: | ||||||||||
- λ¬Έμμ μμΉμ λ°λΌ μΆκ° 컨νΈλ‘€ λλ μ 보λ₯Ό νμνκ±°λ μ¨κΉλλ€. | ||||||||||
- μ¬μ©μκ° νμ΄μ§ λκΉμ§ μ€ν¬λ‘€ ν λ λ λ§μ λ°μ΄ν°λ₯Ό λ‘λν©λλ€. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
Here's a small function to show the current scroll: | ||||||||||
λ€μμ νμ¬ μ€ν¬λ‘€μ νμνλ μμ ν¨μμ λλ€. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
```js autorun | ||||||||||
window.addEventListener('scroll', function() { | ||||||||||
|
@@ -15,23 +15,23 @@ window.addEventListener('scroll', function() { | |||||||||
``` | ||||||||||
|
||||||||||
```online | ||||||||||
In action: | ||||||||||
λμ μ€: | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
Current scroll = <b id="showScroll">scroll the window</b> | ||||||||||
νμ¬ μ€ν¬λ‘€ = <b id="showScroll">scroll the window</b> | ||||||||||
``` | ||||||||||
|
||||||||||
The `scroll` event works both on the `window` and on scrollable elements. | ||||||||||
`scroll` μ΄λ²€νΈλ `window` μ μ€ν¬λ‘€μ΄ κ°λ₯ν μμ λͺ¨λμμ μλν©λλ€. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
## Prevent scrolling | ||||||||||
## μ€ν¬λ‘€ λ°©μ§ | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
How do we make something unscrollable? | ||||||||||
μ΄λ»κ² ν΅μ ν μ μλ κ²μ λ§λ€ μ μμκΉμ? | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
We can't prevent scrolling by using `event.preventDefault()` in `onscroll` listener, because it triggers *after* the scroll has already happened. | ||||||||||
μ€ν¬λ‘€μ΄ μ΄λ―Έ μ€νλ *ν*μ νΈλ¦¬κ±° λλ―λ‘ `onscroll` Listenerμμ `event.preventDefault()`λ₯Ό μ¬μ©νμ¬ μ€ν¬λ‘€μ λ°©μ§ν μ μμ΅λλ€. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
But we can prevent scrolling by `event.preventDefault()` on an event that causes the scroll, for instance `keydown` event for `key:pageUp` and `key:pageDown`. | ||||||||||
κ·Έλ¬λ μ€ν¬λ‘€μ μ λ°νλ μ΄λ²€νΈ(μμ: `key:pageUp` λ° `key:pageDown`μ λν `keydown` μ΄λ²€νΈ)μ λν΄ `event.preventDefault()`λ‘ μ€ν¬λ‘€ νμ§ μλλ‘ ν μ μμ΅λλ€. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
If we add an event handler to these events and `event.preventDefault()` in it, then the scroll won't start. | ||||||||||
μ΄λ²€νΈ νΈλ€λ¬λ₯Ό μ΄λ¬ν μ΄λ²€νΈμ μ΄λ²€νΈ νΈλ€λ¬μ `event.preventDefault()`μ μΆκ°νλ©΄ μ€ν¬λ‘€μ΄ μμλμ§ μμ΅λλ€. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Suggested change
|
||||||||||
|
||||||||||
There are many ways to initiate a scroll, so it's more reliable to use CSS, `overflow` property. | ||||||||||
μ€ν¬λ‘€μ μμνλ λ°©λ²μ μ¬λ¬ κ°μ§κ° μμΌλ―λ‘ CSS, `overflow` νλ‘νΌν°λ₯Ό μ¬μ©νλ κ²μ΄ λ μμ μ μ λλ€. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
Here are few tasks that you can solve or look through to see applications of `onscroll`. | ||||||||||
λ€μμ `onscroll`μ μ ν리μΌμ΄μ μ 보기 μν΄ ν΄κ²°νκ±°λ μ΄ν΄λ³Ό μ μλ λͺ κ°μ§ κ³Όμ μ λλ€. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.