From 22538d6697e448b20d2ae0f0c66161f85e540c00 Mon Sep 17 00:00:00 2001 From: Rob Sayre Date: Sat, 25 Jun 2011 09:42:59 -0700 Subject: [PATCH] Make the log auto-scroll if the scrollbar is near the bottom, but maintain position if it isn't. --- test/test_slave.html | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/test_slave.html b/test/test_slave.html index d685eeaf2..5652a5860 100644 --- a/test/test_slave.html +++ b/test/test_slave.html @@ -194,9 +194,17 @@ function clear(ctx) { ctx.restore(); } +/* Auto-scroll if the scrollbar is near the bottom, otherwise do +nothing. */ +function checkScrolling() { + if ((stdout.scrollHeight - stdout.scrollTop) <= stdout.offsetHeight) { + stdout.scrollTop = stdout.scrollHeight; + } +} + function log(str) { stdout.innerHTML += str; - window.scrollTo(0, stdout.getBoundingClientRect().bottom); + checkScrolling(); }