Skip to content

Commit

Permalink
Define a fixed height for chat and auto-scroll.
Browse files Browse the repository at this point in the history
  • Loading branch information
trestletech committed Jan 10, 2014
1 parent 2102545 commit c89ced3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
20 changes: 19 additions & 1 deletion sendOnEnter.js
Expand Up @@ -7,4 +7,22 @@ jQuery(document).ready(function(){
jQuery('#send').click();
}
});
})
})

// We don't yet have an API to know when an element is updated, so we'll poll
// and if we find the content has changed, we'll scroll down to show the new
// comments.
var oldContent = null;
window.setInterval(function() {
var elem = document.getElementById('chat');
if (oldContent != elem.innerHTML){
scrollToBottom();
}
oldContent = elem.innerHTML;
}, 300);

// Scroll to the bottom of the chat window.
function scrollToBottom(){
var elem = document.getElementById('chat');
elem.scrollTop = elem.scrollHeight;
}
13 changes: 12 additions & 1 deletion shinychat.css
@@ -1,6 +1,8 @@
#chat {
padding: .5em;
border: 1px solid #777;
height: 300px;
overflow: scroll;
}

.user-change, .user-exit, .user-enter {
Expand All @@ -26,4 +28,13 @@
color: #AAA;
text-align: right;
padding: 30px 0;
}
}

html, body {
height: 100%;
}

.fill {
min-height: 100%;
height: 100%;
}

0 comments on commit c89ced3

Please sign in to comment.