Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jeremenichelli/steer
Script that fires events only when the scrolling direction changes
https://github.com/jeremenichelli/steer
Last synced: 23 days ago
JSON representation
Script that fires events only when the scrolling direction changes
- Host: GitHub
- URL: https://github.com/jeremenichelli/steer
- Owner: jeremenichelli
- License: mit
- Created: 2014-06-08T14:58:46.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-03-26T19:24:04.000Z (over 8 years ago)
- Last Synced: 2024-10-18T19:40:55.837Z (about 1 month ago)
- Language: JavaScript
- Homepage: https://jeremenichelli.github.io/steer
- Size: 33.2 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# steer
[![Build Status](https://travis-ci.org/jeremenichelli/steer.svg)](https://travis-ci.org/jeremenichelli/steer)
Script that fires events **only** when the user changes the scrolling direction.
### Install
Include the distribution file in your project
```html
```
also available on **bower**
```bash
bower install steer --save
```... and **npm** as **steerjs**
```bash
npm install steerjs --save
```### steer.set()
This method ```set``` lets you configure the actions to be called everytime the user changes the scroll direction.
```js
steer.set({
up: function() {
// do something when the user starts scrolling up
},
down: function() {
// do something when the user starts scrolling down
}
});
```In case you need it, the **y** position when the function was fired is passed as an argument.
```js
steer.set({
up: function(y) {
console.log('up method fire at ' + y + 'px!');
}
});
```### steer.trigger()
You can pass a flag called ```events``` with the value ```false``` in the configuration object so no listeners are added **on scroll**.
```js
steer.set({
events: false,
up: function(y) {
console.log('up method fire at ' + y + 'px!');
}
});
```Then for **steer** to work you need to call `steer.trigger()` in the scroll event in your code.
```js
window.addEventListener('scroll', function() {
// do other things on scroll ...
steer.trigger();
}, false);
```### Size
**steer** is really light, **307 bytes** minified and gzipped!
### Browser support
This library works perfect in the latest version of all modern browsers and Internet Explorer 9+, and requires `addEventListener` support.
### Contribute
Feel free to rise an issue or suggest a change that you think that can improve this code.