Skip to content

[css-scroll-snap-2] Better snap physics and customization? #8549

Open
@flackr

Description

@flackr

We've had requests from developers (e.g. airbnb, google search) to customize the fling curve of snap point scrolls. A common cause or desire is to align behavior, which itself seems partially motivated from the way that browsers haven't given special treatment to scrolling physics for certain snap use cases in the same way that the experiences being emulating have given them different physics.

scroll-snap-stop is often used as a simple form of control over the physics (forcing a stop at each item), but even when the typical interaction is to scroll one item at a time developers often want to still allow flings to cross multiple items.

I think expectations may vary based on the size of snap items and lengths of documents, e.g.:

  • For long articles with headers that may want to snap, having snap behave similar to normal scrolling likely matches expectations
  • For lists with snap points on each item, there is often an expectation that a standard length flick will move about a page of items. The experiment in crbug.com/1189696 shows that for such use cases it may be as simple as adjusting fling distances to meet expectations here. A paginated book would likely have similar expectations.
  • Scrolling within a large snap point should probably match document scrolling but may want to prefer seeing the end of the current snap point rather than jumping to the next snap point.

While some cases the browser may be able to "just do the right thing", I think there are cases that would be helpful if the developer could give the browser a hint what kind of category things fall into.

Some possible ideas:

  • Add a scroll-snap-distance: item | page | document which hints whether the UA should treat a typical fling as traversing the distance of one item, one page, or a document scroll (the current behavior). Alternately, it could take a length.
  • Add a scroll-snap-friction: # which applies some amount of friction to getting to scrolling past each subsequent snap point.
  • Something else?

I'm not sure what the exact right solution is here but there seems to be a common developer need to apply different physics to different scenarios.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions