Skip to content

Commit

Permalink
Don't autoscroll if we're scrolled up more than 50px from the bottom …
Browse files Browse the repository at this point in the history
…of the log.
  • Loading branch information
scottgonzalez committed Apr 28, 2010
1 parent 0aeea97 commit fdf8cef
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions demo/web/js/client.js
Expand Up @@ -3,11 +3,9 @@
var title = document.title,
colors = ["green", "orange", "yellow", "red", "fuschia", "blue"],
channel = nodeChat.connect("/chat"),
scroll = true,
log,
message;

// TODO: Turn off auto scrolling if user has scrolled up from the bottom
// TODO: handle connectionerror

$(function() {
Expand Down Expand Up @@ -142,10 +140,13 @@ $(channel).bind("msg", function(event, message) {
})

// Auto scroll list to bottom
.bind("join part msg", function(){
window.setTimeout(function() {
log.scrollTop(log[0].scrollHeight);
}, 10);
.bind("join part msg", function() {
// auto scroll if we're within 50 pixels of the bottom
if (log.scrollTop() + 50 >= log[0].scrollHeight - log.height()) {
window.setTimeout(function() {
log.scrollTop(log[0].scrollHeight);
}, 10);
}
});

// handle login (choosing a nick)
Expand Down

0 comments on commit fdf8cef

Please sign in to comment.