scroll-snap-api
Interact with CSS scroll-snap.
Zero dependencies.
Automatically accounts for scroll-padding
.
Install
yarn add scroll-snap-api
npm install --save scroll-snap-api
Or use directly
import * as scrollSnapApi from 'https://cdn.pika.dev/scroll-snap-api';
Usage
Scroll an element to the next snap position in a direction
import { scrollSnapToNext } from 'scroll-snap-api';
scrollSnapToNext( scrollingElement, 'right' );
Get the possible scroll positions
import { getScrollSnapPositions } from 'scroll-snap-api';
const scroll = getScrollSnapPositions( scrollingElement );
Get the raw snap positions
Note: these are not scroll positions.
import { getSnapPositions } from 'scroll-snap-api';
const snap = getSnapPositions( scrollingElement );

TODO
- More documentation
- Support
dir="rtl"