aboutsummaryrefslogtreecommitdiff
path: root/files/ko/web/api/globaleventhandlers/onscroll/index.html
blob: e4221b328e3d9058172aac59164c60bf4d3a5dd4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
---
title: GlobalEventHandlers.onscroll
slug: Web/API/GlobalEventHandlers/onscroll
translation_of: Web/API/GlobalEventHandlers/onscroll
---
<div>{{ApiRef("HTML DOM")}}</div>

<div>{{domxref("GlobalEventHandlers")}} 의 <strong><code>onscroll</code></strong> 이벤트는 {{event("Event_handlers")}} 의 <code>scroll</code> 이벤트를 상속받았습니다.</div>

<div></div>

<div>document view 나  element 가 스크롤이 됬을 때 이벤트가  발생합니다.</div>

<div></div>

<div class="blockIndicator note">
<p><strong>Note:</strong> <code>onscroll</code> 과 {{domxref("GlobalEventHandlers.onwheel", "onwheel")}} 이벤트를 혼동하지 마세요. <code>onwheel</code> 보통 휠의 회전을 처리하고, <code>onscroll</code>은 객체의 내용의 스크롤을 처리합니다.</p>
</div>

<h2 id="Syntax">Syntax</h2>

<pre class="syntaxbox"><em>target</em>.onscroll = <em>functionRef</em>;
</pre>

<h3 id="Value">Value</h3>

<p><code>functionRef</code> 은(는) 함수 표현식 또는 함수 이름 이며, 이 객체는 오직 {{domxref("UIEvent")}} 객체만 인수로 받습니다.</p>

<p>오직 하나의 <code>onscroll</code> 이벤트만 하나의 객체에 할당 할 수 있습니다.  <a href="https://developer.mozilla.org/ko/docs/Web/API/EventTarget/addEventListener" title="EventTarget의 addEventListener() 메서드는 지정한 이벤트가 대상에 전달될 때마다 호출할 함수를 설정합니다."><code>EventTarget.addEventListener()</code></a> 를 사용하여  <code><a href="https://developer.mozilla.org/ko/docs/Web/Reference/Events/scroll" rel="nofollow" title="/ko/docs/Web/Reference/Events/scroll">scroll</a></code> 이벤트를 정의 할 수 있습니다.</p>

<h2 id="Example">Example</h2>

<p>다음 예제는  {{HtmlElement("textarea")}}에 발생한 스크롤 이벤트 결과를 출력해 줍니다.</p>

<h3 id="HTML">HTML</h3>

<pre class="brush: html">&lt;textarea&gt;1 2 3 4 5 6 7 8 9&lt;/textarea&gt;
&lt;p id="log"&gt;&lt;/p&gt;</pre>

<h3 id="CSS">CSS</h3>

<pre class="brush: css">textarea {
  width: 4rem;
  height: 8rem;
  font-size: 3rem;
}</pre>

<h3 id="JavaScript">JavaScript</h3>

<pre class="brush: js">const textarea = document.querySelector('textarea');
const log = document.getElementById('log');

textarea.onscroll = logScroll;

function logScroll(e) {
  log.textContent = `Scroll position: ${e.target.scrollTop}`;
}</pre>

<h3 id="Result">Result</h3>

<p>{{EmbedLiveSample("Example", 700, 200)}}</p>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('HTML WHATWG','#handler-onscroll','onscroll')}}</td>
   <td>{{Spec2('HTML WHATWG')}}</td>
   <td></td>
  </tr>
  <tr>
   <td>{{SpecName("DOM3 Events", "#event-type-scroll", "onscroll")}}</td>
   <td>{{Spec2("DOM3 Events")}}</td>
   <td>Initial definition</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>



<p>{{Compat("api.GlobalEventHandlers.onscroll")}}</p>

<h2 id="See_also">See also</h2>

<ul>
 <li><a href="/en-US/docs/Web/API/Document/scroll_event">Document: <code>scroll</code> event</a></li>
 <li><a href="/en-US/docs/Web/API/Element/scroll_event">Element: <code>scroll</code> event</a></li>
</ul>