I have a div element where it is scrollable
<script>
let scrollBoxObj;
$: scrollBoxObj = document.getElementById("chat-box");
$: if (!(scrollBoxObj === undefined) && scrollBoxObj.scrollTop < scrollBoxObj.scrollHeight) {
scrollBoxObj.scrollTop = scrollBoxObj.scrollHeight;
}
</script>
<div id="scrollBox" class="h-screen w-auto chat-box border border-orange rounded">
<div id="chat-box" style="margin: 0" class="chat-box">
{#each chatBox as { user, content, type}}
<MessageBox {user} message={content} {type} />
{/each}
</div>
</div>
<style>
.chat-box {
overflow-y: auto;
}
</style>
i am trying to auto scroll down when a new message is added. but it is not reactive. or i didn't understand how reactivity works in svelte. i also tried to assign scrollBoxObj in onMount but it was still the same result didn't work.