litera / jquery-scrollintoview

Animated scroll into view jQuery plugin
http://erraticdev.blogspot.com/2011/02/jquery-scroll-into-view-plugin-with.html
231 stars 136 forks source link

Scroll Parent is inside another Parent #11

Open johnygold opened 11 years ago

johnygold commented 11 years ago

I have three DIV's. Scrollintoview is used to scroll to DIV 3, that is inside DIV 2. This works. However, DIV 2 is inside DIV 1, and the part where DIV 3 is visible is not into view from the viewpoint of DIV 1. So I have to scroll down DIV 1 (which is the actually the body of my document) to get DIV 3 visible. Is there a way to also scroll the DIV 1 automatically so DIV 3 becomes visible?

litera commented 11 years ago

First of all if you have scrollable inside scrollable you may have a usability problem. That's why I didn't implement nested plugin. First of all it would be much more complex to make (under particular circumstances) and second of all I would rather encourage developers to rethink their UI.

but apart from this and depending on your particular situation, you may call scrollintoview twice:

  1. on div2 which scrolls it into view within div1
  2. and then on div3 which scrolls it into view within div2

This will work if div2 is smaller in size than div1 otherwise some part of the scrolled-in element may still be beyond visible viewport and scrolling the third element within that one may still render it beyond visible part.

As mentioned: rethink your UI because even without any automated scrolling users are likely frustrated by this double deep scrolling which makes it pretty hard to find what they're looking for.