Script that fires events only when the scrolling direction changes
MIT License
Script that fires events only when the user changes the scrolling direction.
Include the distribution file in your project
<script src="js/steer.min.js"></script>
also available on bower
bower install steer --save
... and npm as steerjs
npm install steerjs --save
This method set
lets you configure the actions to be called everytime the user changes the scroll direction.
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.
steer.set({
up: function(y) {
console.log('up method fire at ' + y + 'px!');
}
});
You can pass a flag called events
with the value false
in the configuration object so no listeners are added on scroll.
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.
window.addEventListener('scroll', function() {
// do other things on scroll ...
steer.trigger();
}, false);
steer is really light, 307 bytes minified and gzipped!
This library works perfect in the latest version of all modern browsers and Internet Explorer 9+, and requires addEventListener
support.
Feel free to rise an issue or suggest a change that you think that can improve this code.