-
Notifications
You must be signed in to change notification settings - Fork 265
/
Copy pathscroll.xml
115 lines (112 loc) · 4.58 KB
/
scroll.xml
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?xml version="1.0"?>
<entries>
<desc>Bind an event handler to the "scroll" event, or trigger that event on an element.</desc>
<entry type="method" name="on" return="jQuery">
<title>scroll event</title>
<desc>Bind an event handler to the "scroll" event.</desc>
<signature>
<added>1.7</added>
<argument name=""scroll"" type="string">
<desc>The string <code>"scroll"</code>.</desc>
</argument>
<argument name="eventData" type="Anything" optional="true">
<desc>An object containing data that will be passed to the event handler.</desc>
</argument>
<argument name="handler" type="Function">
<desc>A function to execute each time the event is triggered.</desc>
<argument name="eventObject" type="Event" />
</argument>
</signature>
<longdesc>
<div class="warning">
<p>This page describes the <code>scroll</code> event. For the deprecated <code>.scroll()</code> method, see <a href="/scroll-shorthand/"><code>.scroll()</code></a>.</p>
</div>
<p>The <code>scroll</code> event is sent to an element when the user scrolls to a different place in the element. It applies to <code>window</code> objects, but also to scrollable frames and elements with the <code>overflow </code>CSS property set to <code>scroll</code> (or <code>auto</code> when the element's explicit height or width is less than the height or width of its contents).</p>
<p>For example, consider the HTML:</p>
<pre><code>
<div id="target" style="overflow: scroll; width: 200px; height: 100px;">
Lorem ipsum dolor sit amet, consectetur adipisicing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis nostrud exercitation
ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit
esse cillum dolore eu fugiat nulla pariatur. Excepteur
sint occaecat cupidatat non proident, sunt in culpa qui
officia deserunt mollit anim id est laborum.
</div>
<div id="other">
Trigger the handler
</div>
<div id="log"></div>
</code></pre>
<p>The style definition is present to make the target element small enough to be scrollable:</p>
<figure>
<img src="/resources/0042_05_11.png" alt=""/>
<figcaption>Figure 1 - Illustration of the rendered HTML</figcaption>
</figure>
<p>The <code>scroll</code> event handler can be bound to this element:</p>
<pre><code>
$( "#target" ).on( "scroll", function() {
$( "#log" ).append( "<div>Handler for `scroll` called.</div>" );
} );
</code></pre>
<p>Now when the user scrolls the text up or down, one or more messages are appended to <code><div id="log"></div></code>:</p>
<p>
<samp>Handler for `scroll` called.</samp>
</p>
<p>To trigger the event manually, use <code>.trigger( "scroll" )</code>:</p>
<pre><code>
$( "#other" ).on( "click", function() {
$( "#target" ).trigger( "scroll" );
} );
</code></pre>
<p>After this code executes, clicks on <samp>Trigger the handler</samp> will also append the message.</p>
<p>A <code>scroll</code> event is sent whenever the element's scroll position changes, regardless of the cause. A mouse click or drag on the scroll bar, dragging inside the element, pressing the arrow keys, or using the mouse's scroll wheel could cause this event.</p>
</longdesc>
<example>
<desc>To do something when your page is scrolled:</desc>
<code><![CDATA[
$( "p" ).clone().appendTo( document.body );
$( "p" ).clone().appendTo( document.body );
$( "p" ).clone().appendTo( document.body );
$( window ).on( "scroll", function() {
$( "span" ).css( "display", "inline" ).fadeOut( "slow" );
} );
]]></code>
<css><![CDATA[
div {
color: blue;
}
p {
color: green;
}
span {
color: red;
display: none;
}
]]></css>
<html><![CDATA[
<div>Try scrolling the iframe.</div>
<p>Paragraph - <span>Scroll happened!</span></p>
]]></html>
</example>
<category slug="events/browser-events"/>
<category slug="version/1.0"/>
<category slug="version/1.7"/>
</entry>
<entry type="method" name="trigger" return="jQuery">
<title>scroll event</title>
<desc>Trigger the "scroll" event on an element.</desc>
<signature>
<added>1.0</added>
<argument name=""scroll"" type="string">
<desc>The string <code>"scroll"</code>.</desc>
</argument>
</signature>
<longdesc>
<p>See the description for <a href="#on1"><code>.on( "scroll", ... )</code></a>.</p>
</longdesc>
<category slug="events/browser-events"/>
<category slug="version/1.0"/>
</entry>
</entries>