Forum Moderators: open

Message Too Old, No Replies

Maintain position while content increases in size

how to set the proper vertical scroll value upon content change

         

alexis

7:39 pm on Sep 28, 2009 (gmt 0)

10+ Year Member



I have a page with enough content to have a big vertical scrollbar. Upon the click of a button, hidden elements get displayed which causes the page to grow bigger vertically.

I would like to keep in place what's in the middle of the screen so that the content seems to expand from the middle of the screen. The problem is that the elements that get unhidden aren't consistent, some paragraphs don't change size while others triple in size so just using scrollTo based on proportions isn't working, especially when you look at content towards the bottom.

Any suggestion on how to achieve this? The individual DIVs are generally never higher than the screen size so I'm thinking it would be nice to target the DIV closest to the middle and make it stay there with something smart.

whoisgregg

2:37 am on Sep 30, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you could determine an target <div> to be the "anchor" that is inside the current view and store it's ID and current scroll offset, then when new elements are displayed/hidden, you find that original <div> and it's new scroll offset and adjust accordingly. However, you'd have to give the other elements time to draw, so you might get some flicker. I can't think of another approach off the top of my head, but I'll post again if I think of one. :)