JavaScript scrollTop problem
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/.
精彩评论