blob: 0a0f2b80b3a1b43cf9787b16a7a3835b005587ad (
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
|
jquery-scrollstop
=================
This plugin fires two events on `window` when scrolling starts and stops:
`scrollstart` and `scrollstop`.
## Example
The example shows a small box in the upper left that says "SCROLLING" and
colors the body different colors when scrolling: http://ssorallen.com/jquery-scrollstop/
## Usage
`scrollstart` fires after the first scroll event and won't fire again until
after a `scrollstop` event is fired.
`scrollstop` fires after no `scroll` events have fired for 250 milliseconds.
```js
$(window)
.on("scrollstart", function() {
// Paint the world yellow when scrolling starts.
$(document.body).css({background: "yellow"});
})
.on("scrollstop", function() {
// Paint it all green when scrolling stops.
$(document.body).css({background: "green"});
})
```
### Configuration
#### latency
`latency` is the minimum time between the last scroll event and when the
`scrollstop` event fires. Set `$.event.special.scrollstop.latency` to the
desired number of milliseconds (default: 250).
```js
// Configure time between final scroll event and
// `scrollstop` event to 650ms (default is 250ms).
$.event.special.scrollstop.latency = 650;
```
##### latency per element
Latency can be configured per-element by passing options when the event listener
is bound. If multiple event listeners are bound to the same element, only the
data from the first event listener will set the configuration.
```js
// Configure latency to 650ms for #scrolling-div
$("#scrolling-div").on("scrollstop", {latency: 650}, function() { ... });
```
### jQuery Version Support
The plugin is tested in jQuery 1.2.3+ and jQuery 2.0.3+.
### Attribution
James Padolsey's jQuery scrollstop plugin that fires an event when scrolling
stops for minimum amount of time.
Originally code copied from
http://james.padolsey.com/javascript/special-scroll-events-for-jquery/
|