Skip to content

Instantly share code, notes, and snippets.

@rogeriolino
Created January 16, 2015 16:30
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 rogeriolino/f291f4f1ba958393b336 to your computer and use it in GitHub Desktop.
Save rogeriolino/f291f4f1ba958393b336 to your computer and use it in GitHub Desktop.
jQuery window scroll helper
(function($) {
$.winscroll = function(fn, restrictions) {
restrictions = $.extend({ minY: 0, minX: 0, maxY: Infinity, maxX: Infinity }, restrictions);
$(window).on('scroll', function() {
var y = $(document).scrollTop(),
x = $(document).scrollLeft();
if (y >= restrictions.minY && y <= restrictions.maxY && x >= restrictions.minX && x <= restrictions.maxX)
{
fn(x, y);
}
});
};
})(jQuery);
@rogeriolino
Copy link
Author

Using:

$.winscroll(function(x, y) {
    console.log(y);
}, { minY: 200, maxY: 400 });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment