You need to use .offset()to get the correct position value, for example:
$('html, body').animate({ scrollTop: $('#div').offset().top }, 'slow');
.offset returns the current position of the element relative to the document.
Links: . position () , . offset ()
source
share