I have this code:
<div id="conversationDiv" style="overflow:auto">
<label>What is your name?</label><input type="text" id="name" />
<button id="sendName" onclick="sendName();updateScroll();">Send</button>
<p id="response"></p>
</div>
And I have this javascript function which I run after I click on 'Send' button and it keeps running after 1 second interval.
<script type="text/javascript">
function updateScroll() {
setInterval(function(){ var element = document.getElementById("conversationDiv");
element.scrollTop = element.scrollHeight; }, 1000);
}
</script>
This is my sendName() function if anyone wants to see:
function sendName() {
var name = document.getElementById('name').value;
stompClient.send("/app/hello", {}, JSON.stringify({ 'name': name }));
}
But the problem is, my scroll bar is never at the bottom.
I am running a Websocket connection and the information keeps coming and coming and when information is enough for scroll bar to appear, I don't want it to go up. I would like it to stay at bottom unless a user scrolls back up him/herself. I don't know why my code is not working. Any help is appreciated. Thanks