Created
April 5, 2011 19:52
-
-
Save zachleat/904389 to your computer and use it in GitHub Desktop.
jQuery scrolly special event
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
/* | |
* 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