Dan
Dan

Reputation: 57891

JavaScript: how much is textarea scrolled?

I want to know how much is the <textarea> or <div style="overflow:scroll"> scrolled. Vertically or horizontally. I expect an answer like this:

function getElementVerticalScroll(el){
      return integer
}

Upvotes: 1

Views: 116

Answers (3)

pimvdb
pimvdb

Reputation: 154858

If you don't want to bring in a library, have a look at the scrollTop property of the element: http://jsfiddle.net/pimvdb/GXGHB/2/.

textarea.scrollTop;

Upvotes: 1

Rob W
Rob W

Reputation: 349042

I've filled in the blank space of your function:

function getElementVerticalScroll(el){
      return el.scrollTop;
}
function getElementHorizontalScroll(el){
      return el.scrollLeft;
}

Upvotes: 1

OptimusCrime
OptimusCrime

Reputation: 14863

Using jQuery, I think $(element).scrollTop(); should do the vertically-lookup. And scrollLeft for horizontal.

Upvotes: 0

Related Questions