Skip to content

Instantly share code, notes, and snippets.

@zachleat
Created April 5, 2011 19:52
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 zachleat/904389 to your computer and use it in GitHub Desktop.
Save zachleat/904389 to your computer and use it in GitHub Desktop.
jQuery scrolly special event
/*
* Changes by Zach Leatherman (@zachleat)
* from James Padolsey Special Scroll Events
* http://james.padolsey.com/javascript/special-scroll-events-for-jquery/
* -------------------------------------------------------
* Dual licensed under the MIT and GPL licenses.
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/copyleft/gpl.html
*/
(function($){
var special = $.event.special;
special.scrolly = {
latency: 30,
setup: function()
{
var timer,
scrolly = -1,
scrollx = -1;
$(this).bind('scroll.scrolly', function(event)
{
var _self = this,
_args = arguments,
$t = $(this);
if (timer) {
clearTimeout(timer);
} else {
scrolly = $t.scrollTop();
scrollx = $t.scrollLeft();
}
timer = setTimeout(function()
{
timer = null;
if(scrolly >= 0 && (scrolly !== $t.scrollTop() || scrollx == $t.scrollLeft())) {
event.type = 'scrolly';
jQuery.event.handle.apply(_self, _args);
}
}, special.scrolly.latency);
});
},
teardown: function() {
$(this).unbind('scroll.scrolly');
}
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment