开发者

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

开发者 https://www.devze.com 2023-01-15 07:07 出处:网络
Is there a 开发者_运维技巧jQuery technique to select all the page controls/divs with a non-zero scrollbar position?

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!


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
     }
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号