3
I’m hoping a determined div
, possessing the attribute overflow-y:auto
, whose height is fixed, is rolled at the end, so an element is added to it.
In this case, I need it to roll until the end, because its height is fixed, but it is not fixed the amount of elements within it. That is, so an element is added with a append
, I need the scroll
roll to the end of this div
.
Currently, I can do this easily with the function scrollTop
, but I think define the value as 9999999
be it much gambit very inelegant.
See something close to what I have:
$(function()
{
$('#div').animate({scrollTop: 9999999}, 500);
});
#div{
height:150px;
background: tomato;
overflow-y: auto;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id='div'>
<li>Conteúdo</li>
<li>Conteúdo</li>
<li>Conteúdo</li>
<li>Conteúdo</li>
<li>Conteúdo</li>
<li>Conteúdo</li>
<li>Conteúdo</li>
<li>Conteúdo</li>
<li>Conteúdo</li>
<li>Conteúdo</li>
<li>Conteúdo</li>
<li>Conteúdo</li>
</div>
How do I roll this
div
until the end, without having to use the current method described above?How to know the size of
scroll
of that div?
To be "more jQuery", I can use the
prop
to not have to access the elements like this?– Wallace Maxters
Yes, it can:
$('#div').scrollTop($('#div').prop("scrollHeight"));
– Anderson Madeira
@Wallacemaxters yes: http://jsfiddle.net/7Lv29w75/1/
– DontVoteMeDown
@Wallacemaxters do not know, I do not see this practice here or in the gringo OS. It is usually placed only in the link and in case the MDN is reliable.
– DontVoteMeDown
Okay, and thanks for the reply :)
– Wallace Maxters
@Wallacemaxters even so, I put a brief.
– DontVoteMeDown
This summary already gives a degree. Sometimes a long explanation is ignored by those who are wanting to learn (mainly me)
– Wallace Maxters