Content loaded in a DIV with automatic scroll bar scrolling

0

I need your help. I'm setting up a chat system, and because I'm a hardhead I'm putting everything in my hands so I can learn. The question is as follows, I have an index.php page and a page called chat.php. I would like to know how to create a script so that I can load the contents of the chat.php page inside a DIV in the index.php page and cause the scroll scroll automatically down. I've tried to do it this way:

<script>
var tempo = window.setInterval(carrega, 5000);
function carrega()
{
$('#chat').load("chat.php");
}
</script>

Of course, the scroll bar will go back to the top after the interval set by the setInterval, even if you scroll down manually. How should I proceed so that she is always down?

    
asked by anonymous 28.03.2016 / 08:15

1 answer

2

You can do this:

$("#chat").load("chat.php");
$("#chat").animate({ scrollTop: $("#div").height() }, 1000);

Source link

    
28.03.2016 / 21:48