2016-07-29 77 views
0

我已經有了一個div,我給它提供了足夠的保證金,幾乎脫離了屏幕。 它將包含文本,用戶將不得不滾動閱讀它。不要問我爲什麼要這樣做,讓我們說背景圖像需要可見。scrollTop div利潤

我希望文本div在一段時間後上移。 動畫的scrolltop似乎沒有與邊緣div,至少,我不能使它的工作。

你們有沒有想出解決方案?

setTimeout(function() { 
    $(window).animate({ 
     scrollTop: $(document).height() 
    }, 300); 
}, 3000); 

這是小提琴。 https://jsfiddle.net/PaulvdDool/1ctt8xto/

+0

你想讓div向上移動,或者窗口要滾動到頂部? –

回答

0

這是選擇的問題 用途:

$('body, html') 

insted的的:

$(document) 

代碼:

console.log("height: " + $(document).height()); 
setTimeout(function() { 
    $('body, html').animate({ 
     scrollTop: $(document).height() 
    }, 300); 
}, 3000); 
+0

這不是問題。問題是,當您嘗試從頂部滾動到文檔的總高度時:D –

0

試試這個:

$(document).ready(function(){ 
    $('#red').delay(1000).animate({marginTop :'50px'}, 500); 
}); 

還有一個小建議:嘗試在css中添加position:fixed。更改marginTop值以符合您的要求。