https://github.com/webdeveric/scroll-watcher
https://github.com/webdeveric/scroll-watcher
scroll scrolling viewport
Last synced: 8 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/webdeveric/scroll-watcher
- Owner: webdeveric
- Created: 2015-06-11T16:00:58.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2016-11-16T16:44:22.000Z (over 9 years ago)
- Last Synced: 2025-10-04T04:36:59.228Z (8 months ago)
- Topics: scroll, scrolling, viewport
- Language: JavaScript
- Size: 33.2 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Scroll Watcher
Perform callbacks when scrolling.
## Example Usage
```javascript
var sw = new ScrollWatcher();
var elm = document.getElementById('some-id');
// Do something like this if you want an infinite scroll feed.
sw.add( function( sw ) {
if ( sw.atBottom ) {
console.log('You are at the bottom.');
// Perform AJAX here to load more content.
}
});
// Do something when an element enters the viewport.
sw.add( function( sw ) {
if ( sw.inViewport(elm) ) {
// Do something here.
// You can remove the callback if you want to run this once.
sw.removeCurrentCallback();
}
});
sw.add( function( sw ) {
if ( someStopCondition ) {
// This removes the event listeners.
sw.stopListening();
}
});
```