Shuo/client/js/libs/jquery/stickyscroll.js

66 lines
1.2 KiB
JavaScript
Raw Normal View History

2014-07-05 00:31:20 +00:00
/*!
* stickyscroll
* https://github.com/erming/stickyscroll
2014-08-04 00:24:22 +00:00
* v2.1.1
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);
});
}
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();
}
});
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);
});
};
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);