jquery - 文档准备就绪时窗口不会滚动到底部
问题描述
我有一个带有一些 jQuery 的网页,它应该在页面加载时滚动到底部:
<script>
$(document).ready(function() {
$("html, body").scrollTop($(document).height());
});
</script>
由于某种原因,当页面加载时,它不会滚动到底部。但是当我这样做时:
<form id="messageinput">
<input type="text" name="message">
<input type="submit" value="">
</form>
<script>
$("#messageinput").submit(function() {
$("html, body").scrollTop($(document).height());
});
</script>
它完美地工作。知道如何解决这个问题吗?有没有更好的方法让它滚动到底部?谢谢!
解决方案
如果您想要不会突然停止的动画,请尝试以下操作:
$('html, body').animate({
scrollTop: $(document).height()-$(window).height()},
1400,
"linear"
);
如果您不关心动画,请使用:
$(myScrollingElement).scrollTop(Number.MAX_SAFE_INTEGER);
推荐阅读
- android - 对齐按钮到 CardView 的底部
- android - Android 将宽度设置为 ConstraintLayout.LayoutParams.MATCH_PARENT 给出 -1
- perl - 我想使用 Perl 将字符串从第二个元素拆分为数组
- docker - 如何在 Spark Standalone Cluster 中从不同服务器添加工作节点
- python - AttributeError:模块“请求”没有属性“发布”
- azure-web-app-service - Azure 应用服务 - 最低 TLS 版本 - 还需要调整主机注册表吗?
- css - 如何在 React 菜单项(Web 应用程序)中对特定菜单项进行换行或换行?
- vim - 在 vim 中编译后如何在新的终端窗口上运行 c++ 程序?
- java - 初始化时表达相互连接
- google-drive-api - 每次都在 GDrive 中上传文件而不记录