【问题标题】:HTML, CSS auto scroll page to bottomHTML、CSS 自动滚动页面到底部
【发布时间】:2017-11-22 01:32:18
【问题描述】:
我已经构建了一个在网页上运行的信使应用程序。随着更多输入的输入(并且页面高度增加),文本离开屏幕底部,用户必须向下滚动。有没有办法自动让页面不断滚动到底部以避免这个问题。页面还有一个引导页眉和页脚,必须始终保持在视图中。这可能与 css 或我将如何实现它?
body {
padding: 5%;
padding-top: 13%;
background-image: url(/img/bg.jpg);
background-size: cover;
background-attachment: fixed;
}
【问题讨论】:
标签:
javascript
jquery
html
css
scroll
【解决方案1】:
您可以使用 jQuery(或 JavaScript)来完成此操作。但是你不能只在 CSS 中做到这一点。
这是你的新代码:
setInterval(function () {
$("html, body").scrollTop($("body").height());
},10);
//Stick to bottom code
setInterval(function () {
$("html, body").scrollTop($("body").height());
},10);
//Expanding body width
// - This isn't what you'd add to your code
setInterval(function () {
$("<div>")
.addClass("build")
.appendTo("#container");
},500);
div.build {
width:100%;
height:200px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="container">
</div>