Skip to content

Instantly share code, notes, and snippets.

@R2D221
Created June 10, 2015 17:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save R2D221/a71157308bd0322a5e4d to your computer and use it in GitHub Desktop.
Save R2D221/a71157308bd0322a5e4d to your computer and use it in GitHub Desktop.
(function(){
var special = jQuery.event.special,
uid1 = 'D' + (+new Date()),
uid2 = 'D' + (+new Date() + 1);
special.scrollstart = {
setup: function() {
var timer,
handler = function(evt) {
var _self = this,
_args = arguments;
if (timer) {
clearTimeout(timer);
} else {
evt.type = 'scrollstart';
jQuery.event.handle.apply(_self, _args);
}
timer = setTimeout( function(){
timer = null;
}, special.scrollstop.latency);
};
jQuery(this).on('scroll', handler).data(uid1, handler);
},
teardown: function(){
jQuery(this).off( 'scroll', jQuery(this).data(uid1) );
}
};
special.scrollstop = {
latency: 300,
setup: function() {
var timer,
handler = function(evt) {
var _self = this,
_args = arguments;
if (timer) {
clearTimeout(timer);
}
timer = setTimeout( function(){
timer = null;
evt.type = 'scrollstop';
jQuery.event.handle.apply(_self, _args);
}, special.scrollstop.latency);
};
jQuery(this).on('scroll', handler).data(uid2, handler);
},
teardown: function() {
jQuery(this).off( 'scroll', jQuery(this).data(uid2) );
}
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment