OrElse
OrElse

Reputation: 9959

Jquery scroll to a div tag

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');
});

Upvotes: 5

Views: 9095

Answers (2)

jAndy
jAndy

Reputation: 236002

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

Upvotes: 8

Dan Heberden
Dan Heberden

Reputation: 11068

This is nice, as well:

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

Upvotes: 0

Related Questions