Merge pull request #262 from thelounge/xpaw/sticky

Improve sticky scroll
This commit is contained in:
Jérémie Astori 2016-04-29 00:15:50 -04:00
commit d171e3c390
2 changed files with 33 additions and 61 deletions

View File

@ -1,67 +1,34 @@
/*!
* stickyscroll
* https://github.com/erming/stickyscroll
* v2.2.0
*/
(function($) { (function($) {
$.fn.unsticky = function() {
return this.unbind(".sticky");
};
$.fn.sticky = function() { $.fn.sticky = function() {
if (this.size() > 1) {
return this.each(function() {
$(this).sticky(options);
});
}
var isBottom = false;
var self = this; var self = this;
var stuckToBottom = true;
this.unbind(".sticky"); self
this.on("beforeAppend.sticky", function() { .on("scroll.sticky", function(e) {
isBottom = isScrollBottom.call(self); stuckToBottom = self.isScrollBottom();
}); })
.on("msg.sticky", function() {
if (stuckToBottom) {
self.scrollBottom();
}
})
.scrollBottom();
this.on("afterAppend.sticky", function() { return self;
if (isBottom) {
self.scrollBottom();
}
});
var overflow = this.css("overflow-y");
if (overflow == "visible") {
overflow = "auto";
}
this.css({
"overflow-y": overflow
});
$(window).unbind(".sticky");
$(window).on("resize.sticky", function() {
self.scrollBottom();
});
this.scrollBottom();
return this;
}; };
$.fn.scrollBottom = function() { $.fn.scrollBottom = function() {
return this.each(function() { var el = this[0];
$(this).animate({scrollTop: this.scrollHeight}, 0); this.scrollTop(el.scrollHeight);
});
};
$.fn.isScrollBottom = isScrollBottom;
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; return this;
}; };
$.fn.isScrollBottom = function() {
var el = this[0];
return el.scrollHeight - el.scrollTop - el.offsetHeight <= 30;
};
})(jQuery); })(jQuery);

View File

@ -656,15 +656,20 @@ $(function() {
} }
viewport.removeClass("lt"); viewport.removeClass("lt");
$("#windows .active").removeClass("active"); $("#windows .active")
.removeClass("active")
.find(".chat")
.unsticky();
var chan = $(target) var chan = $(target)
.addClass("active") .addClass("active")
.trigger("show") .trigger("show")
.css("z-index", top++) .css("z-index", top++);
.find(".chat")
.sticky() var chanChat = chan.find(".chat");
.end(); if (chanChat.length > 0) {
chanChat.sticky();
}
var title = "The Lounge"; var title = "The Lounge";
if (chan.data("title")) { if (chan.data("title")) {