2011-03-15 45 views
1

我前面加一個jquery的AJAX()調用jquery的自動滾動()成功[如何]

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

那麼我該怎麼做呢?

回答

3

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

1

你好,你可以使用這個,ID是元素ID在頁面必須滾動。

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

繼續笑。