Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1307 from tomaszdurka/issue-1307
Browse files Browse the repository at this point in the history
BREAKING: Add jquery event scrollTop
  • Loading branch information
tomaszdurka committed Jul 1, 2014
2 parents 8ffc4b2 + 7b8f1a1 commit 8b54f02
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 57 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Author: CM
*/
(function($) {
var checkDelay = 100;
var preloadMultiple = 3;

var checkScrollTop = _.throttle(function(event) {
event.type = 'scrollTop';
var $this = $(this);
var innerHeight = $this.innerHeight();
var distanceFromTop = $this.scrollTop();
var distanceMin = innerHeight * preloadMultiple;
if (distanceFromTop < distanceMin) {
$(this).trigger('scrollTop', [event]);
return true;
}
return false;
}, checkDelay);

$.event.special.scrollTop = {
add: function(handleObj) {
jQuery.event.add(this, 'scroll', checkScrollTop);
jQuery.event.add(this, 'touchmove', checkScrollTop);
},
remove: function(handleObj) {
jQuery.event.remove(this, 'scroll', checkScrollTop);
jQuery.event.remove(this, 'touchmove', checkScrollTop);
}
};

var checkScrollBottom = _.throttle(function(event) {
event.type = 'scrollBottom';
var $this = $(this);
var scrollHeight = $this.is($(window)) ? $('body').prop('scrollHeight') : $this.prop('scrollHeight');
var innerHeight = $this.innerHeight();
var distanceFromBottom = scrollHeight - innerHeight - $this.scrollTop();
var distanceMin = innerHeight * preloadMultiple;
if (distanceFromBottom < distanceMin) {
$(this).trigger('scrollBottom', [event]);
return true;
}
return false;
}, checkDelay);

$.event.special.scrollBottom = {
add: function(handleObj) {
jQuery.event.add(this, 'scroll', checkScrollBottom);
jQuery.event.add(this, 'touchmove', checkScrollBottom);
},
remove: function(handleObj) {
jQuery.event.remove(this, 'scroll', checkScrollBottom);
jQuery.event.remove(this, 'touchmove', checkScrollBottom);
}
};
})(jQuery);

0 comments on commit 8b54f02

Please sign in to comment.