我如何使用jquery向下滚动到iframe或页面的底部?
当前回答
一个简单的函数,跳到整个页面的底部(立即滚动)。它使用内置的. scrolltop()。我还没有尝试将其用于单独的页面元素。
function jumpToPageBottom() {
$('html, body').scrollTop( $(document).height() - $(window).height() );
}
其他回答
scrollTop()返回从可滚动区域的视图中隐藏的像素数,因此给它:
$(document).height()
会超出页面的底部。为了让滚动实际“停止”在页面底部,需要减去当前浏览器窗口的高度。这将允许在需要时使用easing,所以它变成:
$('html, body').animate({
scrollTop: $(document).height()-$(window).height()},
1400,
"easeOutQuint"
);
例如:
$('html, body').scrollTop($(document).height());
之前的回答中提到的脚本,比如:
$("body, html").animate({
scrollTop: $(document).height()
}, 400)
or
((窗口).scrollTop美元(文档).height ());
将不会在Chrome中工作,并将在Safari中跳跃,以防html标签在CSS中溢出:auto;属性集。我花了将近一个小时才弄明白。
如果你想要一个漂亮的缓慢动画滚动,对于任何带有href="#bottom"的锚,这将滚动到底部:
$("a[href='#bottom']").click(function() {
$("html, body").animate({ scrollTop: $(document).height() }, "slow");
return false;
});
您可以随意更改选择器。
一个简单的函数,跳到整个页面的底部(立即滚动)。它使用内置的. scrolltop()。我还没有尝试将其用于单独的页面元素。
function jumpToPageBottom() {
$('html, body').scrollTop( $(document).height() - $(window).height() );
}
推荐文章
- JSHint和jQuery: '$'没有定义
- 用jQuery检查Internet连接是否存在?
- 如何使用滑动(或显示)函数在一个表行?
- 如何用JavaScript截屏一个div ?
- 如何检测“搜索”HTML5输入的清除?
- 当元素从DOM中移除时触发事件
- Ajax成功事件不工作
- 引导下拉与Hover
- jQuery的.bind() vs. on()
- jQuery .live() vs .on()方法,用于在加载动态html后添加单击事件
- 事件。returnValue已弃用。请使用标准的event.preventDefault()
- 如何处理模式关闭事件在Twitter引导?
- 防止浏览器加载拖放文件
- 清除输入文本内的图标
- jQuery为ajax请求返回“parsererror”