|
1 | | - |
2 | | -<!--- |
3 | | -
|
4 | | -This README is automatically generated from the comments in these files: |
5 | | -core-scroll-threshold.html |
6 | | -
|
7 | | -Edit those files, and our readme bot will duplicate them over here! |
8 | | -Edit this file, and the bot will squash your changes :) |
9 | | -
|
10 | | -The bot does some handling of markdown. Please file a bug if it does the wrong |
11 | | -thing! https://github.com/PolymerLabs/tedium/issues |
12 | | -
|
13 | | ---> |
14 | | - |
15 | | -_[Demo and API Docs](https://elements.polymer-project.org/elements/iron-scroll-threshold)_ |
16 | | - |
17 | | - |
18 | | -##<undefined> |
19 | | - |
20 | | -Fired when `lowerTriggered` becomes `true`. |
21 | | - |
22 | | - |
| 1 | +iron-scroll-threshold |
| 2 | +========= |
| 3 | + |
| 4 | +`iron-scroll-threshold` is a utility element that listens for `scroll` events from a |
| 5 | +scrollable region and fires events to indicate when the scroller has reached a pre-defined |
| 6 | +limit, specified in pixels from the upper and lower bounds of the scrollable region. |
| 7 | +This element may wrap a scrollable region and will listen for `scroll` events bubbling |
| 8 | +through it from its children. In this case, care should be taken that only one scrollable |
| 9 | +region with the same orientation as this element is contained within. Alternatively, |
| 10 | +the `scrollTarget` property can be set/bound to a non-child scrollable region, from which |
| 11 | +it will listen for events. |
| 12 | + |
| 13 | +Once a threshold has been reached, a `lower-threshold` or `upper-threshold` event will |
| 14 | +be fired, at which point the user may perform actions such as lazily-loading more data |
| 15 | +to be displayed. After any work is done, the user must then clear the threshold by |
| 16 | +calling the `clearTriggers` method on this element, after which it will |
| 17 | +begin listening again for the scroll position to reach the threshold again assuming |
| 18 | +the content in the scrollable region has grown. If the user no longer wishes to receive |
| 19 | +events (e.g. all data has been exhausted), the threshold property in question (e.g. |
| 20 | +`lowerThreshold`) may be set to a falsy value to disable events and clear the associated |
| 21 | +triggered property. |
| 22 | + |
| 23 | +### Example |
| 24 | + |
| 25 | +```html |
| 26 | +<iron-scroll-threshold on-lower-threshold="loadMoreData"> |
| 27 | + <div>content</div> |
| 28 | +</iron-scroll-threshold> |
| 29 | +``` |
| 30 | + |
| 31 | +```js |
| 32 | + loadMoreData: function() { |
| 33 | + // load async stuff. e.g. XHR |
| 34 | + asyncStuff(function done() { |
| 35 | + ironScrollTheshold.clearTriggers(); |
| 36 | + }); |
| 37 | + } |
| 38 | +``` |
| 39 | + |
| 40 | +### Using dom-repeat |
| 41 | + |
| 42 | +```html |
| 43 | +<iron-scroll-threshold on-lower-threshold="loadMoreData"> |
| 44 | + <dom-repeat items="[[items]]"> |
| 45 | + <template> |
| 46 | + <div>[[index]]</div> |
| 47 | + </template> |
| 48 | + </dom-repeat> |
| 49 | +</iron-scroll-threshold> |
| 50 | +``` |
| 51 | + |
| 52 | +### Using iron-list |
| 53 | + |
| 54 | +```html |
| 55 | +<iron-scroll-threshold on-lower-threshold="loadMoreData" id="threshold"> |
| 56 | + <iron-list scroll-target="threshold" items="[[items]]"> |
| 57 | + <template> |
| 58 | + <div>[[index]]</div> |
| 59 | + </template> |
| 60 | + </iron-list> |
| 61 | +</iron-scroll-threshold> |
| 62 | +``` |
0 commit comments