Page 1 of 1

Autoscroll

Posted: Fri Mar 08, 2013 2:25 am
by ExtremeGaming
I'm making a JQuery chat for my site and I'm having a hard time trying to figure out how to autoscroll the chat to the bottom for both the posting user, and any viewing users, each time a message is posted.

I understand that I could set an interval to automatically scroll to the bottom every so often, but that would interfere with user viewing.

I was thinking of making a call to a file to check for the amount of rows in the database, store the last checked one and compare it to the newest one. If there are more, then perform the scroll?

Any ideas to the subject would be greatly appreciated :D

EDIT: Solved :) If anyone was wondering:
//Updates the chat
function Update(){

     $.ajax({
     
        type: "GET",
        url: "fetch_chat.php",
        data: {  
            'cond': cond,
            'log' : log
            },
        dataType: "json",
        cache: false,
        success: function(data) {
        
            if (data.text != null) {
                for (var i = 0; i < data.text.length; i++) {  
                $('#container').append($(data.text));
            }
            
            document.getElementById('container').scrollTop = document.getElementById('container').scrollHeight;
        
        }  
        
        instanse = false;
        state = data.state;
        setTimeout('Update()', 1);
        
        },
    });
}

Re: Autoscroll

Posted: Sun Mar 10, 2013 9:02 pm
by jacek
Still <3 self-solving topics.