[英]scroll to bottom on page load but will allow to scroll on top
我想在頁面加載時將 div bottom
滾動到頁面底部,但也想在需要時向上滾動以了解如何在沒有任何動畫的情況下將其存檔如何實現此echo "<div id='bottom'><p><b>$from_username</b><br />$message</p></div>";
<script>
function scrollpage() {
function f()
{
window.scrollTo(0,i);
if(status==0) {
i=i+40;
if(i>=Height){ status=1; }
}
setTimeout( f, 0.01 );
}f();
}
var Height=document.documentElement.scrollHeight;
var i=1,j=Height,status=0;
scrollpage();
</script>
這是我到目前為止所擁有的,我可以自動向下滾動但無法在我想要的時候向上滾動,如果我想向上滾動我該怎么辦?
在頁面加載 (jQuery) 時滾動到 Div 的底部,這是我找到的代碼,我需要為您將它們放在一起。
<script>
$( document ).ready(function() {
var d = $('#div1');
d.scrollTop(d.prop("scrollHeight"));
console.log("at the bottom!");
});
</script>
</head>
<body>
<p>top</p>
<div style="max-height: 200px;">
<div id='div1' style='background-color:grey;width:200px;overflow:scroll;overflow-x:hidden;max-height:200px;'>
<p>some text</p><p>some text</p><p>some text</p><p>some text</p><p>some text</p><p>some text</p><p>some text</p><p>some text</p><p>some text</p><p>some text</p><p>some text</p><p>some text</p></div>
</div>
<p>bottom</p>
<p>text under the div</p>
</body>
</html>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.