Last active
August 29, 2015 14:27
-
-
Save hacfi/017cd680f514b4af4c36 to your computer and use it in GitHub Desktop.
This file contains 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
/* | |
* smartscroll: debounced scroll event for jQuery * | |
* based on smartresize by @louis_remi: https://github.com/lrbabe/jquery.smartresize.js * | |
* Copyright 2011 Louis-Remi & lukeshumard * Licensed under the MIT license. * | |
*/ | |
var event = $.event, | |
scrollTimeout; | |
event.special.smartscroll = { | |
setup: function() { | |
$(this).bind( "scroll", event.special.smartscroll.handler ); | |
}, | |
teardown: function() { | |
$(this).unbind( "scroll", event.special.smartscroll.handler ); | |
}, | |
handler: function( event, execAsap ) { | |
// Save the context | |
var context = this, | |
args = arguments; | |
// set correct event type | |
event.type = "smartscroll"; | |
if (scrollTimeout) { clearTimeout(scrollTimeout); } | |
scrollTimeout = setTimeout(function() { | |
jQuery.event.handle.apply( context, args ); | |
}, execAsap === "execAsap"? 0 : 100); | |
} | |
}; | |
$.fn.smartscroll = function( fn ) { | |
return fn ? this.bind( "smartscroll", fn ) : this.trigger( "smartscroll", ["execAsap"] ); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment