1- For when you hit the bottom... of a dom element while scrolling.
1+ For when you hit the bottom (or top) ... of a dom element while scrolling.
22
33### Motivation
44
5- Infinite scrolling plugins do ** way too much** :
6- internally keep track of a scroll hitting the bottom of an element, fetch, then render, and rebind.
5+ Infinite scroll plugins do ** way too much** :
6+ internally keeping track of a scroll hitting the bottom of an element, fetching data,
7+ rerendering, and then rebinding to repeat the process.
78
8- If you have a backbone app that requires infinite scrolling, then you often
9+ If you have a backbone app that requires infinite scrolling, then you often
910have a list view that listens to a collection and handles rendering. ** Infinite scrolling
1011should be as simple as being notified when you've hit the bottom of the (scrollable) element,
1112and letting you call fetch on the proper collection.**
1213
13- After you've ` smack ` ed the bottom, you have the option to call smack (if you want to be notified again).
14+ After you've ` smack ` ed the bottom (or top) , you have the option to call smack (if you want to be notified again).
1415For example, after you've loaded another page of results, you would want to detect when you've
1516smacked the bottom of the element. If you don't have any more results, then you wouldn't want to keep being notified.
1617
@@ -20,7 +21,7 @@ http://jsfiddle.net/TLdSW/3/
2021
2122### Usage
2223
23- Detect when you've scrolled to the bottom of the element
24+ Detect when you've smacked to the bottom (default) of the element
2425
2526``` javascript
2627$ (selector).smack ()
@@ -29,21 +30,44 @@ $(selector).smack()
2930 });
3031```
3132
32- Detect when you've scrolled through 80% of the element
33+ Detect when you've smacked the top of the element
34+
35+ ``` javascript
36+ $ (selector).smack ({ edge: ' top' })
37+ .done (function () {
38+ });
39+ ```
40+
41+
42+ Detect when you've smacked 80% of the way to the bottom of the element
3343
3444``` javascript
3545$ (selector).smack ({ threshold: 0.8 })
3646 .done (function () {
37- // Do stuff like fetch from a collection
3847 });
3948```
4049
41- Detect when you've scrolled within 200px of the bottom of the element
50+ Detect when you've smacked 80% of the way to the top of the element
51+
52+ ``` javascript
53+ $ (selector).smack ({ edge: ' top' , threshold: 0.8 })
54+ .done (function () {
55+ });
56+ ```
57+
58+ Detect when you've smacked within 200px of the bottom of the element
4259
4360``` javascript
4461$ (selector).smack ({ threshold: ' 200px' })
4562 .done (function () {
46- // Do stuff like fetch from a collection
63+ });
64+ ```
65+
66+ Detect when you've smacked within 200px of the top of the element
67+
68+ ``` javascript
69+ $ (selector).smack ({ edge: ' top' , threshold: ' 200px' })
70+ .done (function () {
4771 });
4872```
4973
@@ -52,8 +76,7 @@ Detect when smacking the bottom of the page itself
5276``` javascript
5377$ (window ).smack ()
5478 .done (function () {
55- // Do stuff like fetch from a collection
56- });
79+ });
5780```
5881
5982### Example infinite scroll
@@ -81,13 +104,11 @@ var that = this;
81104* represents scrolling through anywhere from 0 to 100% of the element or, if a pixel value is supplied,
82105the distance from the bottom of the element
83106
84- * default = 1; you're notified when you hit the bottom of the element
107+ * default = 1; you're notified when you hit the bound edge of the element
108+
109+ * edge* : allows you to bind to either the ` 'top' ` or ` 'bottom' ` (default) edge of an element
85110
86111### Building & Testing
87112
88113* To build, run ` npm install ` and then ` grunt `
89- * To run the tests, point your browser to ` test/runner.html `
90-
91- ### Changelog
92-
93- v1.1 Threshold supports pixel values (thanks @TheBox193 )
114+ * To run the tests, point your browser to ` test/runner.html `
0 commit comments