2012-04-17 24 views
0

我使用的是DIV標籤而不是iFrame的FYI。我想向訪問者展示所有可用的內容。我發現這個代碼會自動滾動頁面加載到底部,然後回到頂部。但我希望它從底部開始,並滾動到頂部。這裏是我發現的代碼:如何在頁面加載從底部開始,然後自動滾動到頂部?

(function($){ 
    $.fn.downAndUp = function(time, repeat){ 
     var elem = this; 
     (function dap(){ 
      elem.animate({scrollTop:elem.outerHeight()}, time, function(){ 
       elem.animate({scrollTop:0}, time, function(){ 
        if(--repeat) dap(); 
       }); 
      }); 
     })(); 
    } 
})(jQuery); 
$("html").downAndUp(1000, 2) 

在此先感謝!

+0

問題是什麼? – 2012-04-17 19:53:55

+0

因此,有大量樣本會在頁面加載時自動滾動到頁面底部。我期待着做相反的事情。從底部開始並自動滾動到頂部。 – jmcclaire 2012-04-17 20:53:42

回答

0

這適用於自動移動到頂部..

$(document).ready(function() { 
    // Goes to the bottom onLoad 
    $(document).scrollTop($(document).height());  

    // This animates you back to the top  
    $('body, html').animate({scrollTop:0}, 'slow');  
});​ 

如果你想要一個事件後滾動與$('body, html')像這樣的東西更換行:

$('someElement').click(function{ 
    $('body, html').animate({scrollTop:0}, 'slow'); 
}); 

編輯我的jsFiddle示例:http://jsfiddle.net/NxFaR/2/

+0

仍然不適合我...感謝。 – jmcclaire 2012-04-17 21:12:29

+0

你用什麼jQuery Lib? – 2012-04-17 21:13:14

+0

我從jQuery的網站(1.7.2)下載了最新的。以下是我如何附加它: jmcclaire 2012-04-18 13:40:24

相關問題