-
Notifications
You must be signed in to change notification settings - Fork 719
[css-scroll-snap-1] re-snapping after layout with animations #4609
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Interesting point! So I think the actions we should take to accept your proposal are:
|
The CSS Working Group just discussed
The full IRC log of that discussion |
Added the following paragraph to the re-snapping section:
And made the following edits to 'scroll-behavior':
@majido @tabatkins @smfr Lmk if the edits look good. |
This edits lgtm and achieve the desired outcome. Thanks for the edit. /cc @flackr |
Filed an issue for Blink |
Context
The specification requires the browsers to re-snap after any content/layout changes. It also prefers re-snapping to the same element as before but if that element never existed or no longer exists then snapping to a new element is done.
We have been implementing this in Chrome and noticed an interesting implication of this: if one adds a single snap area to an existing snap container with no snap area, the container has to snap to the area.
This introduces an interesting new way to do "scroll-into-view" effects using only css. For example see this demo where I make the
:active
element to be a snap area which forces its ancestor scroller to re-snap which centers the element. I think this is interesting usecase of scroll-snap. However one limitation of this is that at the moment these re-snapping effects are not necessarily animated so the re-snap is jarring. Also webdevs don't have any control on such animations if we add them. I like to see if we can rectify this by making it animated but also exposing more control over such snap animations to web-devs.Current Chrome Behavior
In Chrome we have decided to not animate layout-induced re-snapping in general. I think this makes sense in most re-snapping cases where we are re-snapping to the same element and the scroll snapping effect should not really be noticed by the user. But when we are re-snapping to a different element I think we should consider allowing animations.
The specification leaves it up to user agent whether to animate or not animate any particular snap operations. So we could just animate these in Chrome and I plan to experiment with this. At the same time I think it makes sense to give web authors control on the animation aspect of scroll-snapping since in some usecases they may not want any animations. Below I suggest one proposal to do this.
Proposal
We already have scroll-behavior to control programmatic scroll animations. So a simple solution is to have its definition expanded to control any scroll snap animation as a result of CSSOM scrolling APIs or re-snapping.
So the proposal suggestion has two parts:
A) Continue to leave animation decision up to user-agent but add a note that suggest user agent should consider animating when re-snap to different element.
B) Specify that
scroll-behavior
controls any scroll-snap animations that are not initiated by user. (This includes any CSSOM scrolling APIs that snap which I think they already did, and more importantly any animations that is introduced due to re-snapping)Here is btw is the current wording for
scroll-behavior
:The text was updated successfully, but these errors were encountered: