-
Notifications
You must be signed in to change notification settings - Fork 8
/
jquery.bottom-1.0.js
43 lines (39 loc) · 1.03 KB
/
jquery.bottom-1.0.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
* jQuery.bottom
* Dual licensed under MIT and GPL.
* Date: 2010-04-25
*
* @description Trigger the bottom event when the user has scrolled to the bottom of an element
* @author Jim Yi
* @version 1.0
*
* @id jQuery.fn.bottom
* @param {Object} settings Hash of settings.
* @return {jQuery} Returns the same jQuery object for chaining.
*
*/
(function($){
$.fn.bottom = function(options) {
var defaults = {
// how close to the scrollbar is to the bottom before triggering the event
proximity: 0
};
var options = $.extend(defaults, options);
return this.each(function() {
var obj = this;
$(obj).bind("scroll", function() {
if (obj == window) {
scrollHeight = $(document).height();
}
else {
scrollHeight = $(obj)[0].scrollHeight;
}
scrollPosition = $(obj).height() + $(obj).scrollTop();
if ( (scrollHeight - scrollPosition) / scrollHeight <= options.proximity) {
$(obj).trigger("bottom");
}
});
return false;
});
};
})(jQuery);