Skip to content

Commit

Permalink
Merge pull request #3 from raphaelcrv/scroll-bottom
Browse files Browse the repository at this point in the history
feat(scroll):automatically scroll down
  • Loading branch information
dericeira authored Dec 17, 2018
2 parents 371211d + 3c2aa36 commit 17cdcb5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions assets/js.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ $(document).ready(function(){
var text = $("#textarea").val();
$("#textarea").val('');
var time = new Date();
$(".chat").append('<li class="self"><div class="msg"><span>' + $("#nickname").val() + ':</span><p>' + text + '</p><time>' + time.getHours() + ':' + time.getMinutes() + '</time></div></li>');
socket.emit("send", text);

$(".chat").append('<li class="self"><div class="msg"><span>' + $("#nickname").val() + ':</span><p>' + text + '</p><time>' + time.getHours() + ':' + time.getMinutes() + '</time></div></li>');

socket.emit("send", text);
// automatically scroll down
document.getElementById('bottom').scrollIntoView();
}
});

Expand All @@ -36,8 +38,9 @@ $(document).ready(function(){

socket.on("chat", function(client,msg) {
if (ready) {
var time = new Date();
$(".chat").append('<li class="other"><div class="msg"><span>' + client + ':</span><p>' + msg + '</p><time>' + time.getHours() + ':' + time.getMinutes() + '</time></div></li>');
var time = new Date();
$(".chat").append('<li class="field"><div class="msg"><span>' + client + ':</span><p>' + msg + '</p><time>' + time.getHours() + ':' + time.getMinutes() + '</time></div></li>');

}
});

Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<ol class="chat">

</ol>

<div id='bottom'></div>
<input class="textarea" type="text" placeholder="Type here!" id="textarea" />
</div>
<script src="node_modules/jquery/dist/jquery.min.js"></script>
Expand Down

0 comments on commit 17cdcb5

Please sign in to comment.