views:

19

answers:

2

Is there a jQuery technique to select all the page controls/divs with a non-zero scrollbar position?

I'm trying to solve a problem faced by many; essentially after a partial asp.net postback all the controls/divs that had a scrollbar with a non-zero value (ie: were scrolled down to some position) are reset to the zero (top of the scrollbar).

My approach is to have a jQuery script save all the scrollbar positions for all the controls/divs contained on a page and after the postback, restore all the scroll bar positions.

Is it possible, can it even work? If it is, how do I use jQuery to select all the divs with scrollbars and then save those positions.

Thanks!

A: 

This question may answer yours: http://stackoverflow.com/questions/616210/reset-scroll-position-after-async-postback-asp-net

cofiem
That relates to the scroll position of the page, he's asking about the scroll position of elements within the page.
Ender
+1  A: 

As far as I know, there is no way to select elements by whether or not they have a scrollbar. If I were to do this, I think my approach would be to target elements that could have scrollbars, then test to see if the scrollTop = 0. For example:

$('div, select[size]').each(function() {
     //test for non-zero scrollTop
     if ($(this).scrollTop() != 0) {
         //save the element by id and the scrollTop value
         //maybe use a cookie, or a string that can be passed
         //between server and client
     }
});
Ender