[Bug 17152] Support centering an element when scrolling into view.

https://www.w3.org/Bugs/Public/show_bug.cgi?id=17152

--- Comment #2 from Thaddee TYL <thaddee.tyl@gmail.com> 2012-06-19 22:17:52 UTC ---
Some additional discussion occurred on the mailing-list.

As a result, the proposal has changed a little.

The WebIDL corresponding to this proposal is the following:

    partial interface Element {
      void scrollIntoView(ScrollPosition options);
    };

    dictionary ScrollPosition {
      float horizontal = 0.5;
      float vertical = 0.5;
      boolean evenIfViewed = false;
    };

The following paragraph is non-normative.

`horizontal` and `vertical` are meant as percentages of
the viewport width minus the width of the bounding box of the element, and
the viewport height minus the height of the bounding box of the element,
respectively.

(Having a boolean flag does what is already specified.)

Having a dictionary as a parameter runs the following algorithm:

1. If the Document associated with the element to be scrolled into view is not
same origin with the Document associated with the element or viewport
associated with the scrolling box, terminate these steps.

2. If `evenIfViewed` is false:
- If the bounding box of the element this method is applied to is completely
out of the viewport, scroll the element to ((innerWidth of the window -
offsetWidth of the element) * horizontal ; (innerHeight of the window -
offsetHeight of the element) * vertical).
- Else if the element is partially visible:
 * If the lower part of the bounding box of the element this method is applied
to is partially visible, align the top of the border box of the element to be
scrolled into view with the top of the scrolling box,
 * If the higher part of the bounding box of the element this method is applied
to is partially visible, align the bottom of the border box of the element to
be scrolled into view with the bottom of the scrolling box,
 * If the right part of the bounding box of the element this method is applied
to is partially visible, align the left of the border box of the element to be
scrolled into view with the left of the scrolling box,
 * If the left part of the bounding box of the element this method is applied
to is partially visible, align the right of the border box of the element to be
scrolled into view with the right of the scrolling box,

3. If `evenIfViewed` is true, scroll the element to ((innerWidth of the window
- offsetWidth of the element) * horizontal ; (innerHeight of the window -
offsetHeight of the element) * vertical).

4. If scrolling the element caused content to move queue a task to fire an
event named scroll at the element, unless a task to fire that event at that
element was already queued.

Finally, a polyfill for this proposal has been implemented, and is available
for public consumption at <http://jsbin.com/3/ilecok/13/edit?javascript>.


Robert O'Callahan raised concerns related to CSS-regions, which may cause
elements to be fragmented between several scrollable containers. The
specification I give above depends on the concept of "scrolling an element",
which should be changed anyway to accommodate this possibility.

-- 
Configure bugmail: https://www.w3.org/Bugs/Public/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.

Received on Tuesday, 19 June 2012 22:17:56 UTC