JQuery 在点击时滚动到锚点?
基本上我有这个函数是一个创建分页的类。我想以某种方式使用平滑滚动将页面移回评论容器 div 的顶部,但不确定我需要在哪里或使用什么功能来执行此操作。
var Comments = function(options) {
this.options = {
id: 0,
page: 0,
object: null,
name: null,
parentid: 0,
folder: './'
};
this.options = $.extend(this.options, options || {});
this.getComments = function(page) {
this.options.page = page;
var object = this.options.object;
var data = 'objid=' + this.options.name;
$.ajax({
type: "GET",
url: this.options.folder + 'backend.php',
data: data,
success: function(msg){
object.html(msg);
}
});
};
this.getComments(this.options.page);
});
我想在成功的 getComments 函数中做一些事情,将其移动到容器的 ID。有什么好的办法吗?
Basically I have this function is a class that creates pagination. I want to somehow use a smooth scroll to move the page back to the top of the comment container div but am unsure where or what function I would need to do that.
var Comments = function(options) {
this.options = {
id: 0,
page: 0,
object: null,
name: null,
parentid: 0,
folder: './'
};
this.options = $.extend(this.options, options || {});
this.getComments = function(page) {
this.options.page = page;
var object = this.options.object;
var data = 'objid=' + this.options.name;
$.ajax({
type: "GET",
url: this.options.folder + 'backend.php',
data: data,
success: function(msg){
object.html(msg);
}
});
};
this.getComments(this.options.page);
});
I'd like to get do something in the success getComments function that moves it up to the ID of the container. Is there a good way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果你的评论div的ID为
comment-div
,那么你可以这样做:你可以根据需要将速度调整为缓动,只需检查
animate
文档了解详细信息。If your comment div has an ID of
comment-div
, then you can do this:You can adjust the speed as easing as needed, just check the
animate
documentation for details.