QInfiniteScroll setScrollPosition? #9150
-
Hey, sorry for possibly idiot question, Is there a way to set scroll position of infinite scroll component? const el = chatScroll.value && chatScroll.value.$el;
if (el) {
const isScrolledToBottom = el.scrollHeight - el.clientHeight <= el.scrollTop + 1;
if (isScrolledToBottom) {
await nextTick();
el.scrollTop = el.scrollHeight - el.clientHeight;
}
} doesn't seem to work |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Here's the source code from a chat app that scrolls down when a new message is send: The relevant code is in the |
Beta Was this translation helpful? Give feedback.
-
Solved this using quasars QScrollArea <q-scroll-area ref="chatScroll" class="full-height col q-px-md">
<q-infinite-scroll
v-if="chatScroll && messages.length && currentContactCard"
reverse
:offset="50"
@load="load"
>
</q-infinite-scroll>
</q-scroll-area> And const chatScroll = ref<QScrollArea | null>(null);
watch(
messages,
async (newMessages) => {
if (chatScroll.value) {
const isClientMessage = ...;
const scrollContainer = chatScroll.value.getScrollTarget() as HTMLDivElement;
const isScrolledToBottom =
scrollContainer.scrollHeight - scrollContainer.clientHeight <= scrollContainer.scrollTop + 1;
if (isScrolledToBottom || isClientMessage) {
await nextTick();
chatScroll.value.setScrollPosition(
scrollContainer.scrollHeight - scrollContainer.clientHeight
);
}
}
},
{ immediate: true }
); |
Beta Was this translation helpful? Give feedback.
Solved this using quasars QScrollArea
And