0

你能告诉我如何做垂直自动滚动吗?实际上,我正在研究套接字编程,并且在定期间隔后获取数据。

如果数据超过页面,我需要它开始垂直滚动(不是手动)。用户可以手动进行,但如果她不想这样做,它应该开始垂直滚动。

这是我的代码:

<div data-role="content" data-theme="d">
    <div class="container">
        <div id="timeID" class="left"></div>
    </div>        

function nativePluginResultHandler(result) {
    var currentTime = new Date()
    var hours = currentTime.getHours()
    var minutes = currentTime.getMinutes()
    if (minutes < 10) {
        minutes = "0" + minutes
    }
    var lines = result.split('<br/>');
    $.each(lines, function () {
        $('#timeID').append("<b>" + hours + ":" + minutes + " " + "</b> " + this + "<br/>");
    });
}

我需要自动滚动 div timeID

4

1 回答 1

3

试试这个简单的例子

<div id="scroll_y" style="width:100%;height:500px;">
<!--put your all stuff Here-->
<div>

#scroll_y {
   overflow-y:scroll;
}

setInterval(function () {
   $('#timeID').append('it works' + new Date());
    var elem = document.getElementById('timeID');// just to scroll down the line 
    elem.scrollTop = elem.scrollHeight;
},30);
于 2013-07-27T05:02:08.000 回答