开发者

JavaScript scrollTop problem

开发者 https://www.devze.com 2023-02-26 20:42 出处:网络
Long story short, I need to get the total scroll size for a text area, in a unit scrollTop can relate to, but I have no idea how.

Long story short, I need to get the total scroll size for a text area, in a unit scrollTop can relate to, but I have no idea how.

scrollHeight, this, that and everything else seemed to be no help. Any suggestions would be appreciated, but for reference, it needs to be able to set a text area of variable size and length's scroll bar to be exactly in the middle.

Also, I'm using chr开发者_StackOverflow社区ome 12 if that matters.


this may help you :

element.scrollTop = element.scrollHeight - (element.clientHeight / 2);


This works for me:

$('#foo').scrollTop($('#foo')[0].scrollHeight / 2);

And a demo thing: http://jsfiddle.net/Rgyk4/8/.

0

精彩评论

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