-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f392932
commit aaa14d0
Showing
8 changed files
with
681 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# scroll-snap-api | ||
|
||
Interact with [CSS scroll-snap](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Scroll_Snap). | ||
|
||
## Install | ||
|
||
```shell | ||
yarn add scroll-snap-api | ||
|
||
npm install --save scroll-snap-api | ||
``` | ||
|
||
Or import directly | ||
|
||
```js | ||
import * as scrollSnapApi from 'https://cdn.pika.dev/scroll-snap-api'; | ||
``` | ||
|
||
## Usage | ||
|
||
### Scroll an element to the next snap position in a direction | ||
|
||
```js | ||
import { scrollSnapToNext } from 'scroll-snap-api'; | ||
|
||
scrollSnapToNext( scrollingElement, 'right' ); // 'left', 'right', 'up', 'down' | ||
``` | ||
|
||
### Get the possible scroll positions | ||
|
||
```js | ||
import { getScrollSnapPositions } from 'scroll-snap-api'; | ||
|
||
const scroll = getScrollSnapPositions( scrollingElement ); | ||
|
||
/* | ||
{ | ||
x: [ 0, 100, 150, 200 ], | ||
y: [ 0, 200, 400, 600, 800 ], | ||
} | ||
*/ | ||
``` | ||
|
||
### Get the raw snap positions | ||
|
||
Note: these are not scroll positions. | ||
|
||
```js | ||
import { getSnapPositions } from 'scroll-snap-api'; | ||
|
||
const snap = getSnapPositions( scrollingElement ); | ||
|
||
/* | ||
{ | ||
x: { | ||
start: [ 0, 100 ], | ||
center: [ 300 ], | ||
end: [ 500 ], | ||
}, | ||
y: { | ||
start: [ 0 ], | ||
center: [ 250, 500, 750 ], | ||
end: [ 1000 ], | ||
}, | ||
} | ||
*/ | ||
``` | ||
|
||
## TODO | ||
|
||
- More documentation | ||
- Support `dir="rtl"` |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.