2014-03-05 207 views
0

所以,我有一個工作的jQuery腳本,使頁面滾動到底部時,單擊按鈕。我打算再次這樣做,但不是滾動到底部,而是希望它滾動到頁面的頂部。這是我的代碼;jquery - 滾動到頂部

function scrolldown() { //Scroll to bottom 
$("html, body").animate({ scrollTop: $(document).height() }, 1250); 
}; 

function scrollup(){ //Scroll to top 
$("html, body").animate({ scrollTop: $(document).top() }, 1250); 
}; 

請幫我弄清楚我需要做什麼,以便我的腳本能夠按照我的要求進行操作。謝謝!

+0

將這項工作:'$( 「HTML,身體」),動畫({scrollTop的: 0},1250);'?? – WickyNilliams

+0

它的確如此,它也可以在括號內沒有html的情況下工作。 –

回答

1

只使用$("html, body").animate({ scrollTop: 0 }, 1250);代替

1

試試這個:

function scrollup(){ //Scroll to top 
    $("body").animate({ scrollTop: 0 }, 1250); 
};