this.chatroom.append(this.chatroom_input);
this.container.append(this.chatroom);
+ this.is_at_end = true;
+ this.suppress_scroll_events = null;
+ this.chat.onscroll = () => {
+ if (!this.suppress_scroll_events) {
+ this.is_at_end = this.chat.scrollTop + this.chat.clientHeight > this.chat.scrollHeight - 10;
+ }
+ };
+
if (close) {
const close_button = document.createElement("button");
close_button.classList.add("game-close");
}
set_error_text(text) {
- const is_at_end = this.chat.scrollTop + this.chat.clientHeight == this.chat.scrollHeight;
this.chat.append(this.chat_element("chatroom-error", "«error»", text));
- if (is_at_end) {
+ if (this.is_at_end) {
this.chat.scrollTo({
top: this.chat.scrollHeight - this.chat.clientHeight,
behavior: "smooth"
});
+ window.clearTimeout(this.suppress_scroll_events);
+ this.suppress_scroll_events = window.setTimeout(() => this.suppress_scroll_events = null, 500);
}
}
take_action(user_action, initialising) {
- const is_at_end = this.chat.scrollTop + this.chat.clientHeight == this.chat.scrollHeight;
switch (user_action.action.action) {
case "Join":
this.seats.set(user_action.username, user_action.action.seat);
console.error("Unknown action for chatroom", user_action);
break;
}
- if (is_at_end) {
+ if (this.is_at_end) {
this.chat.scrollTo({
top: this.chat.scrollHeight - this.chat.clientHeight,
behavior: "smooth"
});
+ window.clearTimeout(this.suppress_scroll_events);
+ this.suppress_scroll_events = window.setTimeout(() => this.suppress_scroll_events = null, 500);
}
}