Skip to content

Commit

Permalink
♻️ Refactor scroll into view
Browse files Browse the repository at this point in the history
  • Loading branch information
haliphax committed Jun 12, 2023
1 parent e178c50 commit 59fcd1d
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions html/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,23 @@ const store = new Vue({
},
});

/** scroll message into view if enabled */
const scrollMessagesIntoView = () =>
hs.scroll &&
requestAnimationFrame(() =>
document.querySelector(".messages").scrollIntoView({
behavior: "smooth",
block: "end",
inline: "start",
})
);

Vue.component("chat-message", {
methods: {
animationEnd(e) {
if (e.animationName == "slide-in") {
this.message.displaying = false;
scrollMessagesIntoView();
} else if (e.animationName == "slide-out") {
this.message.dead = true;
}
Expand Down Expand Up @@ -251,16 +263,7 @@ twitch.on("message", (channel, tags, message, self) => {
store.messages.find((v) => !v.expired).expired = true;
}, constants.DESTRUCT_TIMER);

// scroll message into view if enabled
if (hs.scroll) {
requestAnimationFrame(() =>
document.querySelector(".messages").scrollIntoView({
behavior: "smooth",
block: "end",
inline: "start",
})
);
}
scrollMessagesIntoView();
});
twitch.connect();

Expand Down

0 comments on commit 59fcd1d

Please sign in to comment.