[cssom-view] Allowing scrollIntoView() to only scroll the nearest scroll container

Right now, when you call el.scrollIntoView(), it scrolls *all* scroll
containers in the element's ancestor chain, ensuring that the element
is *definitely* in view when it's done.

This isn't always what you want.  For example, say you have a 3d view
of all the albums in your iTunes library flying around, with each
album showing a cover image and then a list of tracks.  If you're
currently playing a track, you want that track to be visible in the
album's list.  If you try to accomplish this by calling
trackEl.scrollIntoView(), it'll move the entire page such that the
track is at the top of the screen, which probably messes up your
application view.  It would be nice to have a way to just scroll
something into view in its nearest scroll container, as you currently
have to instead measure the element's offsetTop and set scrollTop on
the correct ancestor.

I propose we add a "within" attribute to the ScrollOptions dict,
taking the values "screen" (the default), "container" (indicating
nearest scroll container ancestor) or an Element.  The "scroll an
element into view" algo would then walk the ancestor chain until it
found the specified element, scrolling the element into view in each
scroll container as it passes over them.  If the passed Element isn't
a scroll container, it doesn't scroll at all; if the Element isn't an
ancestor, it throws an error.  (Or maybe it throws on both or fails
silently on both, dunno.)

~TJ

Received on Wednesday, 23 July 2014 01:01:35 UTC