var count = 0; var $console = $('#console'); var $content = $('#content'); var i=0; function addLine() { var line = '' + out + '
'; $(line).appendTo('#content'); i += 0.25; if ($content.height() > $console.height()) { var oldTop = $content.css('top'); var newTop = parseFloat(oldTop) - 20; console.log(oldTop, newTop); $('#content').css('top', newTop + 'px'); } count ++; } setInterval(addLine, 200);