I'm designing a basic chat webpage, but whenever there are more messages than the screen can display without scrolling down, you have to scroll down to see newer messages. is there a way to fix this so that the webpage auto-scrolls (or some similar solution) when a new message is sent? any help would be greatly appreciated. here is my HTML:
<!doctype html>
<html>
<head>
<title>QuickChat</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font: 13px Helvetica, Arial; text-align: center; }
form { background: #666666; padding: 3px; position: fixed; bottom: 0; width: 100%; }
form input { border: 100; padding: 10px; width: 90%; margin-right: .5%; }
form button { width: 9%; background: #FFCC00; border: none; padding: 10px; }
#messages { list-style-type: none; margin: 0; padding: 0; }
#messages li { padding: 5px 10px; }
#messages li:nth-child(odd) { background: #eee; }
main {text-align: center; margin: 0; }
</style>
<form action="">
<input id="m" autocomplete="off" /><button>Send!</button>
</form>
<text>[SYSTEM]: Welcome to the chat! two things you should know: 1. There are no usernames.
I'm working on it, but for right now you can type your messages like [your name] [your message].
2. This chat is fairly secure, but PLEEEASE don't send any secret stuff accross it (like passwords) unless absolutely necessary.
Thanks for using my website! -C
</text>
</head>
<script src="/socket.io/socket.io.js"></script>
<script src="https://code.jquery.com/jquery-1.11.1.js"></script>
<script>
$(function () {
var socket = io();
$('form').submit(function(){
socket.emit('chat message', $('#m').val());
$('#m').val('');
return false;
});
socket.on('chat message', function(msg){
$('#messages').append($('<li>').text('[USER]: ' + msg));
});
});
</script>
<body>
<div id="main">
<ul id="messages"></ul>
</div>
</body>
</html>