溢出时自动滚动到底部自动 [英] auto scroll to bottom when overflow auto

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

问题描述

有谁知道如何通过 jquery 中的事件自动跳转到可滚动区域的底部(如果没有简单的 jquery 解决方案,甚至是 javascript)?

问候

解决方案

<p>我的内容在这里</p>

var myDiv = $("#myDiv");myDiv.animate({ scrollTop: myDiv.attr("scrollHeight") - myDiv.height() }, 3000);

jQuery 1.6 引入了 .prop 并改变了 .attr 的含义,因此 $("#someDiv").attr("scrollHeight") 不会再工作了.

需要改为:$("#someDiv").prop("scrollHeight")

参考.

does anyone know how to automatically jump to the bottom of a scrollable area by event in jquery ( or even javascript if no easy jquery solution)?

regards

解决方案

<div id="myDiv" style="height:300px;overflow:auto;">
    <p>my content here</p>
</div>

var myDiv = $("#myDiv");
myDiv.animate({ scrollTop: myDiv.attr("scrollHeight") - myDiv.height() }, 3000);

Edit:

jQuery 1.6 introduced .prop and changed the meaning of .attr thus $("#someDiv").attr("scrollHeight") won't work anymore.

Need to be changed to: $("#someDiv").prop("scrollHeight")

Reference.

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

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