2017-05-10 17 views
0

我創建了一個函數,該函數使用overflow-y向下滾動div content。 當我剛剛刷新並正確滾動到底部時,此功能起作用。當我從其他網頁(同一網站)來的時候,它會滾動,但幾乎不會到達底部。ScrollTop在刷新頁面時起作用,但當我來自其他鏈接時不起作用

我已經使用console.log來查看它向下滾動多少,甚至在那裏它顯示scrollHeight比div本身大,所以應該是正確的。

我試過用3000ms將setTimeOut放在它周圍,但那不起作用。

setTimeout (function() { 
    $content.animate({ scrollTop: $content.prop("scrollHeight")}, "medium"); 
    console.log($content.prop("scrollHeight")); 
}, 3000) 

我不認爲這是錯誤的代碼,但別的。任何人有想法?

回答

0

animate只能每次打開一個標籤

你應該使用popstate event時間:

function animate(){ 
    $content.animate({ scrollTop: $content.prop("scrollHeight")}, "medium"); 
    console.log($content.prop("scrollHeight")); 
} 
animate(); 
window.onpopstate = function() { 
    animate(); 
}; 
+0

日Thnx答覆,但行爲保持不變。當我刷新它完美的作品,但當我使用鏈接去那裏,它幾乎滾動到底部。 –

相關問題