Skip to content

Commit

Permalink
Fix scrolling
Browse files Browse the repository at this point in the history
  • Loading branch information
Xeleb iOS Developer committed Mar 2, 2018
1 parent bcfed0c commit 503d7bb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
17 changes: 10 additions & 7 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,15 @@ <h2>Chatify - A realtime socket based chat app</h2>
<div class="chat-message-form">
<div class="form-group">
<form action="">
<textarea class="form-control message-input"
autocomplete="off"
id="m"
name="message"
placeholder="Enter message text"></textarea>
<button class="btn btn-warning" type="submit">Send</button>
<input
type="text"
class="form-control message-input"
autocomplete="off"
id="message"
name="message"
placeholder="Enter message text"/>

<button class="btn btn-warning pull-right m-r-sm m-t-sm" type="submit">Send</button>
</form>
</div>
</div>
Expand Down Expand Up @@ -96,7 +99,7 @@ <h2>Chatify - A realtime socket based chat app</h2>
<script type="text/javascript" src="/socket.io/socket.io.js"></script>

<!--Application scripts-->
<script type="text/javascript" src="/js/chatify-socket.js"></script>
<script type="text/javascript" src="/js/chatify.js"></script>


</body>
Expand Down
8 changes: 5 additions & 3 deletions public/js/chatify-socket.js → public/js/chatify.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
$(document).ready(function () {
var socket = io();
$('form').submit(function () {
socket.emit('send-message', $('#m').val());
$('#m').val('');
socket.emit('send-message', $('#message').val());
$('#message').val('');
return false;
});

Expand Down Expand Up @@ -30,7 +30,9 @@ $(document).ready(function () {
`
);
window.scrollTo(0, document.body.scrollHeight);

var messages = document.getElementById('messages');
messages.scrollTop = messages.scrollHeight;
});

socket.on('update-users', function (data) {
Expand Down

0 comments on commit 503d7bb

Please sign in to comment.