views:

100

answers:

2

I use the following in order scrolling to top. How could i edit it so the top is set by a div tag?

var pageRequestManager = Sys.WebForms.PageRequestManager.getInstance();
pageRequestManager.add_endRequest(function() {
$('html, body').animate({ scrollTop: 0 }, 'slow');
});
+1  A: 

You need to use .offset() to get the correct position value like:

$('html, body').animate({ scrollTop: $('#div').offset().top }, 'slow');

.offset returns the current position of an element relative to the document.

References: .position(), .offset()

jAndy
Use `.offset()` instead which gives position relative to the document as `scrollTop` also works relative to the document itself.
Tatu Ulmanen
@Tatu Ulmanen: just added that while you were commenting :)
jAndy
A: 

This is nice, as well:

http://plugins.jquery.com/project/ScrollTo

Dan Heberden