1
Hi, boys from the O.R.! All right?
I need your help with Jquery so that the scrollbar of the div "conteudo2" scrolls to the end when you click on the "Open" button".
Simple, right? The problem is that when I load the content through the request . load, the scroll bar does not scroll until the end of the div.
When I do the same test with . append, I get success and scroll bar descends to the end without major problems.
$(function() {
$(".abrir").on('click', function(){
$('#conteudo1').addClass('d-none');
$('#conteudo2').removeClass('d-none');
$( "#conteudo2" ).load( "pagina.html" );
//Exemplo de uso com .append (Funciona corretamente)
/*for(var i = 0; i < 1000; i++){
$( "#conteudo2" ).append( "<p>Teste</p>" );
}*/
//scroll to last message
$('#conteudo2').delay(1000).animate ({
scrollTop: $('#conteudo2')[0].scrollHeight
});
});
});
HTML
<div id="container">
<div id="conteudo1">
<div class="abrir">Abrir</div>
</div>
<div id="conteudo2" class="d-none">
<div id="resultado"></div>
</div>
Note: No. Jsfiddle I provide the script with the 2 commands (.append and .load), but I could not load the contents in the command. load, because this command will load a second page, I couldn’t include this page in Jsfiddle for testing. So it won’t work in Jsfiddle. But if you try it locally, you’ll see that the scroll bar doesn’t go down until the end.
Help me fix the script with the . load command and make the scroll bar go down to the end?! And, if possible, explain to me why this happens?! Why it works with . append and not . load, if both load content in the div?
Link to the Jsfiddle: https://jsfiddle.net/Joka89/ge4yburk/7/
Thank you very much!
The method load jQuery, it doesn’t really work on these stackoverflow and jsfiddle sites, because it relies on two pages for its operation, which these sites don’t. As for your code, I tested it here on my machine and it worked perfectly with the load as well as the scroll. If you are using the same code you posted to jsfiddle, then it has to work. What you have to make sure is whether this html page. has enough content to make a scroll in the div that loads it.
– LeAndrade