Jquery滚动到div标签。

时间:2022-11-03 10:11:46

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

我使用以下命令滚动到顶部。我怎么编辑它,所以顶部是由div标签设置的?

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

2 个解决方案

#1


8  

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

需要使用.offset()获取正确的位置值,如:

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

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

.offset返回元素相对于文档的当前位置。

References: .position(), .offset()

引用:.position(),.offset()

#2


0  

This is nice, as well:

这也很好:

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

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

#1


8  

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

需要使用.offset()获取正确的位置值,如:

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

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

.offset返回元素相对于文档的当前位置。

References: .position(), .offset()

引用:.position(),.offset()

#2


0  

This is nice, as well:

这也很好:

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

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