Not a Name
Not a Name

Reputation: 1003

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 chrome 12 if that matters.

Upvotes: 1

Views: 2427

Answers (2)

Blender
Blender

Reputation: 298146

This works for me:

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

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

Upvotes: 0

Farzin Zaker
Farzin Zaker

Reputation: 3606

this may help you :

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

Upvotes: 1

Related Questions