2

Here is my script:

$(document).ready(function () {
    $('div').animate({
        scrollTop: $('#content').offset().top
    }, 'slow');
});

What I want is, the scroll should go at the bottom of the div. Is it possible?

P.S.
  • 15,970
  • 14
  • 62
  • 86
zahid hasan emon
  • 6,023
  • 3
  • 16
  • 28
  • Possible duplicate of [Get bottom and right position of an element](https://stackoverflow.com/questions/9872128/get-bottom-and-right-position-of-an-element) – hsz Nov 28 '17 at 09:48
  • Add the #content.height() to #content.offset().top like #content.offset().top+#content.height() – Roy Bogado Nov 28 '17 at 09:48

1 Answers1

2

"What I want is, the scroll should go at the bottom of the div"

Now you scroll to the top of the div, because offset().top calculates, where this div starts. If you want to scroll to the bottom of the div, you can simply add the height of the div too, like this:

scrollTop: $('#content').offset().top + $('#content').height()
P.S.
  • 15,970
  • 14
  • 62
  • 86