用于“控制台外观”的新行的javascript scrollTop循环

时间:2011-07-27 17:54:59

标签: javascript scrolltop

我有一个数组,在持续时间之后将一行发布到名为引号的div。现在我希望div用每个添加的行滚动到底部,但是我遇到了一些麻烦。如果改变了什么,我正在使用firefox。

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);            

}

1 个答案:

答案 0 :(得分:1)

嗯......我让它工作了......不,你不能将三个参数传递给setTimeout但你可以将Scroll调用放在ShowLinesHelper中

http://jsfiddle.net/xDjpx/1