Neetu sharma
Neetu sharma

Reputation: 148

Auto scrolling content of div in jQuery

Can you please tell me how to do vertical auto scroll? Actually I am working on socket programming and I am getting data after a regular interval of time.

I need if the data goes more than page it start vertical scrolling (not manually). User is able to do do manually, but if she does not want to do that it should start scrolling vertically .

Here is my code:

<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/>");
    });
}

I need to automatically scroll the div timeID.

Upvotes: 0

Views: 7830

Answers (1)

Deepak Ingole
Deepak Ingole

Reputation: 15732

Try this simple example

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

Upvotes: 3

Related Questions