thelounge/client/js/libs/jquery/stickyscroll.js

68 lines
1.3 KiB
JavaScript
Raw Normal View History

2014-07-05 00:31:20 +00:00
/*!
* stickyscroll
* https://github.com/erming/stickyscroll
* v2.2.0
2014-07-05 00:31:20 +00:00
*/
(function($) {
$.fn.sticky = function() {
if (this.size() > 1) {
2014-07-06 15:58:57 +00:00
return this.each(function() {
2014-07-05 00:31:20 +00:00
$(this).sticky(options);
});
}
2014-07-05 00:31:20 +00:00
var isBottom = false;
var self = this;
2014-07-07 12:42:46 +00:00
this.unbind(".sticky");
this.on("beforeAppend.sticky", function() {
2014-07-05 00:31:20 +00:00
isBottom = isScrollBottom.call(self);
});
2014-07-07 12:42:46 +00:00
this.on("afterAppend.sticky", function() {
2014-07-05 00:31:20 +00:00
if (isBottom) {
self.scrollBottom();
}
});
2014-07-05 00:31:20 +00:00
var overflow = this.css("overflow-y");
if (overflow == "visible") {
overflow = "auto";
}
this.css({
"overflow-y": overflow
});
2014-08-04 00:24:22 +00:00
$(window).unbind(".sticky");
$(window).on("resize.sticky", function() {
self.scrollBottom();
});
2014-07-07 12:42:46 +00:00
this.scrollBottom();
2014-07-05 00:31:20 +00:00
return this;
};
$.fn.scrollBottom = function() {
return this.each(function() {
$(this).animate({scrollTop: this.scrollHeight}, 0);
});
};
$.fn.isScrollBottom = isScrollBottom;
2014-07-05 00:31:20 +00:00
function isScrollBottom() {
if ((this.scrollTop() + this.outerHeight() + 1) >= this.prop("scrollHeight")) {
return true;
} else {
return false;
}
};
var append = $.fn.append;
$.fn.append = function() {
this.trigger("beforeAppend");
append.apply(this, arguments).trigger("afterAppend")
return this;
};
})(jQuery);