Andy Parker
Posts: 0
Joined: Wed Mar 27, 2013 10:21 am

How To Calculate the Max ScrollTop value for a DIV

I have a DIV named "newschool_div" in a page called timesheets.
In that DIV I have a grid that is populated with rows of school names.
If the school name on a particular row is the one selected from a previous page it is coloured to highlight it.

Also, I am trying to set the div's scrollTop setting to make sure the selected school is visible on the div. I do this by setting the scrollTop element of the DIV to scroll the DIV to have the selected row visible.

My problem is, after a lot of reading and trying, the scrollHeight figure seems to bare no relation to the max scrollTop figure.

for example, by using the code below, the maxScrollTop comes back as 62522, but when I manually scroll the div to the bottom, the scrollTop figure is 3514.....

My question is, how can I calculate the maximum figure for scrollTop for the DIV? the figure should equal the figure I manually see when scrolling all the way to the bottom.....

code
var elem = $("#timesheets_newschool_div");
var maxScrollTop = elem[0].scrollHeight - elem.outerHeight();
/code

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

How To Calculate the Max ScrollTop value for a DIV

Hello Andy,

Could you show on the screenshot, what do you mean with max ScrollTop? Is it the same as it is described here: http://stackoverflow.com/questions/12... ?

Return to “Issues”