Skip to content

[브라우저: 문서, 이벤트, 인터페이스] - [UI 이벤트] - 스크롤 #1669

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions 2-ui/3-event-details/8-onscroll/article.md
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.
예시로 :
- 추가적인 제어나 정보등을 문서상 유저의 위치에 따라 숨기거나 보여줄 수 있습니다.
- 유저가 스크롤하여 페이지의 끝에 도달할 때 까지 추가적인 데이터를 불러옵니다.

Here's a small function to show the current scroll:
현재 스크롤을 보여주는 간단한 함수입니다.

```js autorun
window.addEventListener('scroll', function() {
Expand All @@ -20,18 +20,17 @@ In action:
Current scroll = <b id="showScroll">scroll the window</b>
```

The `scroll` event works both on the `window` and on scrollable elements.
`scroll` 이벤트는 `window` 와 스크롤 가능한 요소 둘 다에 발생합니다.

## Prevent scrolling
## 스크롤 막기

How do we make something unscrollable?
무언가를 스크롤 불가능하게 만드려면 어떻게 해야 할까요?

We can't prevent scrolling by using `event.preventDefault()` in `onscroll` listener, because it triggers *after* the scroll has already happened.
`onscroll` 리스너 안의 `event.preventDefault()`를 통해 스크롤을 막는 건 불가능합니다. 왜냐하면 리스너가 트리거 될 땐 이미 스크롤이 발생한 뒤기 때문입니다.

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` 이벤트엔 위와 같은 방법이 유효합니다.

If we add an event handler to these events and `event.preventDefault()` in it, then the scroll won't start.
이러한 키보드 이벤트에 `event.preventDefault()` 코드로 스크롤이 발생하지 않게 할 수 있습니다.

There are many ways to initiate a scroll, so it's more reliable to use CSS, `overflow` property.

Here are few tasks that you can solve or look through to see applications of `onscroll`.
스크롤을 발생시키는데에는 위 두가지 방법 외에도 다양한 방법들이 있습니다.
그러므로 CSS의 `overflow` 속성을 이용하는 방법이 좀 더 안전할 수 있습니다.