hardlounge/client/js/libs/jquery/stickyscroll.js

35 lines
637 B
JavaScript
Raw Normal View History

2014-07-05 00:31:20 +00:00
(function($) {
2016-04-17 10:50:03 +00:00
$.fn.unsticky = function() {
return this.unbind(".sticky");
};
2016-04-17 10:50:03 +00:00
$.fn.sticky = function() {
2014-07-05 00:31:20 +00:00
var self = this;
2016-04-17 10:50:03 +00:00
var stuckToBottom = true;
self
.on("scroll.sticky", function(e) {
stuckToBottom = self.isScrollBottom();
})
.on("msg.sticky", function() {
if (stuckToBottom) {
self.scrollBottom();
}
})
.scrollBottom();
return self;
2014-07-05 00:31:20 +00:00
};
$.fn.scrollBottom = function() {
2016-04-17 10:50:03 +00:00
var el = this[0];
this.scrollTop(el.scrollHeight);
return this;
2014-07-05 00:31:20 +00:00
};
2016-04-17 10:50:03 +00:00
$.fn.isScrollBottom = function() {
var el = this[0];
return el.scrollHeight - el.scrollTop - el.offsetHeight <= 30;
2014-07-05 00:31:20 +00:00
};
})(jQuery);