[英]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.