jQuery滚动到页面底部 [英] jQuery Scroll To bottom of the page

查看:85
本文介绍了jQuery滚动到页面底部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

页面加载完成后.我希望jQUery能够很好地滚动到页面底部,快速动画,而不是快速/摇动.

After my page is done loading. I want jQUery to nicely scroll to the bottom of the page, animating quickly, not a snap/jolt.

我是否需要像ScrollTo这样的插件?还是jQuery内置的某种方式?

Do iI need a plugin like ScrollTo for that? or is that built into jQuery some how?

推荐答案

您可以通过设置scrollTop属性的动画来动画化向下滚动页面,而无需插件,例如:

You can just animate to scroll down the page by animating the scrollTop property, no plugin required, like this:

$(window).load(function() {
  $("html, body").animate({ scrollTop: $(document).height() }, 1000);
});

请注意使用window.onload(当加载图像时...占据高度)而不是document.ready.

Note the use of window.onload (when images are loaded...which occupy height) rather than document.ready.

要在技术上正确无误,您需要减去窗口的高度,但以上方法可以实现:

To be technically correct, you need to subtract the window's height, but the above works:

$("html, body").animate({ scrollTop: $(document).height()-$(window).height() });


要滚动到特定ID,请使用其 .scrollTop() ,如下所示:


To scroll to a particular ID, use its .scrollTop(), like this:

$("html, body").animate({ scrollTop: $("#myID").scrollTop() }, 1000);

这篇关于jQuery滚动到页面底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆