W3C home > Mailing lists > Public > www-style@w3.org > July 2014

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

From: Tab Atkins Jr. <jackalmage@gmail.com>
Date: Tue, 22 Jul 2014 18:00:48 -0700
Message-ID: <CAAWBYDA+CAS2fKZP84V_oR9tMamR2YLEYGPGxY_giq8d60SZdg@mail.gmail.com>
To: www-style list <www-style@w3.org>
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.)

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

This archive was generated by hypermail 2.3.1 : Monday, 2 May 2016 14:39:23 UTC