2016-09-15 26 views
1

我希望我的頁面自動刷新後自動滾動下來...這是我的代碼如何自動上下滾動。刷新內容,當它達到其結尾「div」

function scroll(speed) { 
$('html, body').animate({ scrollTop: $(document).height() }, speed, function() { 
    $(this).animate({ scrollTop: 0 }, speed); 
}); 
} 

speed = 25000; 

scroll(speed) 
setInterval(function(){scroll(speed)}, speed * 2); 
+0

解釋一點點 – Gopalakrishnan

+0

如果它刷新時碰到底部,那麼你不會看到它返回?你可以在你的第二個動畫中添加另一個完整的函數,像'function(){location.reload(); }'那麼你不應該需要你的setInterval調用。 – Sam0

+0

所以你的意思是@Sam0,我會替換setInterval(function(){scroll(speed)},speed * 2);函數(){location.reload(); } ?? –

回答

1

這裏有一個快速的小提琴:https://jsfiddle.net/manoeuvres/LbLaf8La/添加刷新調用location.reload();在你的第二個電話動畫的「動作完成」的功能,因此它刷新當動畫返回到頂部。

function scroll(speed) { 
$('html, body').animate({ scrollTop: $(document).height() }, speed, function() { 
    $(this).animate({ scrollTop: 0 }, speed, function(){ location.reload(); }); 
}); 
} 

speed = 25000; 

scroll(speed) 
setInterval(function(){scroll(speed)}, speed * 2); // because the page is refreshing I don't think this line gets to get called. but no problem to leave it in.