Skip to content

Commit

Permalink
Builds
Browse files Browse the repository at this point in the history
  • Loading branch information
LachlanArthur committed Apr 14, 2020
1 parent f392932 commit aaa14d0
Show file tree
Hide file tree
Showing 8 changed files with 681 additions and 0 deletions.
72 changes: 72 additions & 0 deletions pkg/README.md
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"`
224 changes: 224 additions & 0 deletions pkg/dist-node/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit aaa14d0

Please sign in to comment.