jquery自动滚动prepend()成功[如何]

时间:2011-03-15 06:49:20

标签: javascript jquery ajax

我在jquery ajax()调用之后返回标记[代码的成功部分如下]

success: function(html){
    $("ul#lists").prepend(html);
    $("ul#lists li:first").fadeIn("slow");
}

当前置成功时,我希望页面自动滚动到前置发生的位置。我不确定语法,但以下是我想要的东西。

success: function(html){
        if($("ul#lists").prepend(html)) {
            //Scroll to the position in the page where the prepend is about to happen
            //something similar to the href="#bookmark' in html. 
        }
        $("ul#lists li:first").fadeIn("slow");
    }

那我该怎么做?

2 个答案:

答案 0 :(得分:3)

你可以使用Ariel Flesler的this插件。

答案 1 :(得分:1)

你可以使用它,id是必须滚动页面的元素id。

$('html, body').animate({scrollTop: $("#"+id).offset().top}, 2000);

继续笑。