2014-07-24 21 views
0

由於某些原因,.scrollTop只能部分工作。它開始滾動並在1-2釐米後停止。這是一個大頁面,容器#topdiv位於頁面的頂部。所有其他功能 - .prepend .hide .close在這裏工作正常。控制檯不顯示任何錯誤。我試過.scrollTo而不是.scrollTop - 結果相同。scrollTop只能部分工作 - 1-2釐米後停止

jQuery(function ($) { 
    $(document).ready(function() { 
     $(document).on('submit', '#saverepost', function (e) { 
      var str = $(this).serialize(); 
      $.ajax({ 
       type: "POST", 
       url: "/script.php", 
       data: str, 
       beforeSend: function() { 
        $('#message').show(); 
        $("#message").html('<img src="/loading.gif" />'); 
       }, 
       success: function (msg) { 
        $.lbox.close(); 
        $("#message").hide(); 
        $("#posts").prepend(msg); 
        $("#topdiv").scrollTop(0); 
       } 
      }); 
      return false; 
     }); 
    }) 
}); 
+1

FYI你有2個文件現成的處理程序 - 您可以安全地刪除其中的一個。 –

+0

你可以發佈你的HTML DOM結構。 – dreamweiver

回答

0

如果你要滾動的實際窗口如果你想要滾動整個頁面,你不針對一個div

$("#topdiv").scrollTop(0); 

做到這一點

$('html,body').scrollTop(0); 
+0

Rory McCrossan說,你有兩個文件準備好陳述。 – alexalexandresq

+0

是的,用$('html,body')它可以工作,但不能用#topdiv。我嘗試刪除secont文檔語句:$('html,body')並將其替換爲:$('#saverepost')。on('submit',function(e){但它不起作用。 – user

+0

You understand我錯了,這是最終的腳本應該如何看起來像http://jsfiddle.net/4VpJN/ – alexalexandresq