2

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?

4

1 回答 1

7

如果您的评论 div 的 ID 为comment-div,那么您可以这样做:

$('html,body').animate({
    scrollTop: '+=' + $('#comment-div').offset().top + 'px'
}, 'fast');

您可以根据需要调整速度,只需查看animate文档了解详细信息。

于 2011-04-01T03:30:09.200 回答