From fdf8cef42ab7438fb2d263a2f7807bbfc2e81d72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Scott=20Gonz=C3=A1lez?= Date: Tue, 27 Apr 2010 22:34:40 -0400 Subject: [PATCH] Don't autoscroll if we're scrolled up more than 50px from the bottom of the log. --- demo/web/js/client.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/demo/web/js/client.js b/demo/web/js/client.js index 190f7be..46c4e6d 100644 --- a/demo/web/js/client.js +++ b/demo/web/js/client.js @@ -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() { @@ -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)