I have an array that posts a line to my div called quotes after a duration. Now I want the div to scroll to the bottom with each added line, but I’m having some troubles. I’m using firefox if that changes anything.
function showLines(){
var arr =
[["Welcome Dave.", 3000],
["I'm afraid that I can't do that.", 500],
["I wouldn't do that Dave.", 2000],
["Now Dave, that wasn't very nice.", 500],
["STOP! That Dave!", 1500],
["All your base belong to us!", 1000]]
, i = 0;
function showLinesHelper()
{
document.getElementById("quotes").innerHTML += arr[i++][0]+'<br />';
if(i < arr.length)
setTimeout(showLinesHelper, arr[i][1]);
}
function Scroll()
{
var objControl=document.getElementById("quotes");
objControl.scrollTop = objControl.scrollHeight;
}
setTimeout(showLinesHelper, arr[0][1], Scroll);
}
Well… I got it to work… no you can’t pass three arguments to setTimeout but you can put the Scroll call inside ShowLinesHelper
http://jsfiddle.net/xDjpx/1