1

Most of the solutions provided in this site use some variants of this code to scroll down to the bottom of a div

 $("ol.overflow-element").animate({
      scrollTop: $("ol.overflow-element li:last-child").position().top
 }, 1000);

I have this in the css

.overflow-element {
    overflow-y: scroll;
    height: 300px;
    padding: 10px;
}

The problem I am having is that it is very inconsistent.

Sometimes it correctly moves to the bottom.

But other times it scrolls somewhere near the top or middle. This happens consistently when the div is already scrolled to the bottom.

Any reason why this is the case? Any alternative, correct impelemntation?

developarvin
  • 4,940
  • 12
  • 54
  • 100

1 Answers1

4

Example code applied on a div is as follows :

//Scroll to bottom
$('div').animate({scrollTop: $('div').get(0).scrollHeight}, 3000);

//$('div').get(0).scrollHeight - will give the full height of div.
//scrollTop - will be used to animate from the current position to page end.
//3000 - will be the duration.

Demo can be found here : http://jsfiddle.net/codebombs/GjXzD/

Sasidhar Vanga
  • 3,384
  • 2
  • 26
  • 47