开发者

auto scroll to bottom when overflow auto

开发者 https://www.devze.com 2022-12-25 01:29 出处:网络
does anyone know how to auto开发者_运维问答matically jump to the bottom of a scrollable area by event in jquery ( or even javascript if no easy jquery solution)?

does anyone know how to auto开发者_运维问答matically 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.


myDiv.attr("scrollHeight")

won't work in recent jQuery versions. You will need to resort to:

myDiv[0].scrollHeight


mm.prop("scrollHeight") does the trick (for jQuery 1.6 and forward).

0

精彩评论

暂无评论...
验证码 换一张
取 消