Scrolling jQuery to div tag

I use the following to scroll up. How can I edit it so that the top element is set by the div tag?

var pageRequestManager = Sys.WebForms.PageRequestManager.getInstance();
pageRequestManager.add_endRequest(function() {
$('html, body').animate({ scrollTop: 0 }, 'slow');
});
+5
source share
2 answers

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 ()

+8
source

All Articles