Skip to content

[css-scroll-snap] Choosing a snap position when children have mixed scroll-snap-align values #780

Closed
@whsieh

Description

@whsieh

(Concerning the Scroll Snap Module Level 1 spec here: https://www.w3.org/TR/2016/CR-css-scroll-snap-1-20161020)

Suppose we have a scroll snap container with 4 children arranged in a 2 by 2 grid, and suppose the children have various mixed values for scroll-snap-align, such as center none, none center, and center. For simplicity, let's say that scroll-snap-margin and scroll-padding are all 0 on the children and container, respectively, and that the scroll-snap-type is both mandatory. Please see the attached diagram for an example.

Given an initial scroll position and a target scroll position where one would normally land in the absence of scroll snapping, what are some guidelines we should follow when selecting the best snap position to land on?

One naive approach is this: model the snap position emitted by each snap area as a line segment, with a start and end position (if neither block or inline axes are none, these positions are the same). For each snap area, compute the point on its line segment closest to the target scroll position. The snap position to choose is then the closest of these closest positions, as long as this position is in the same direction from the initial scroll position as the target scroll position.

Does this seem reasonable?

scroll-snap-example

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions