Created
June 10, 2015 17:48
-
-
Save R2D221/a71157308bd0322a5e4d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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