Skip to content

Commit

Permalink
Add playground
Browse files Browse the repository at this point in the history
  • Loading branch information
lucafalasco committed Apr 7, 2021
1 parent eef2fbb commit 0a44e37
Show file tree
Hide file tree
Showing 28 changed files with 157 additions and 614 deletions.
33 changes: 8 additions & 25 deletions README.md
Expand Up @@ -33,41 +33,24 @@ Call the constructor passing a DOM element and a configuration object as paramet

`unbind()` to remove the listener on the element.

Check out the following code:

```js
import ScrollSnap from 'scroll-snap'

const snapConfig = {
/**
* snap-destination for x and y axes
* should be a valid css value expressed as px|%|vw|vh
*/
// snap-destination for x axis, should be a valid css value expressed as px|%|vw|vh
snapDestinationX: '0%',
// snap-destination for y axis, should be a valid css value expressed as px|%|vw|vh
snapDestinationY: '90%',
/**
* time in ms after which scrolling is considered finished
* [default: 100]
*/
// time in ms after which scrolling is considered finished [default: 100]
timeout: 100,
/**
* duration in ms for the smooth snap
* [default: 300]
*/
// duration in ms for the smooth snap [default: 300]
duration: 300,
/**
* threshold to reach before scrolling to next/prev element, expressed as a percentage in the range [0, 1]
* [default: 0.2]
*/
// threshold to reach before scrolling to next/prev element, expressed as a percentage in the range [0, 1] [default: 0.2]
threshold: 0.2,
/**
* when true, the scroll container is not allowed to "pass over" the other snap positions
* [default: false]
*/
// when true, the scroll container is not allowed to "pass over" the other snap positions [default: false]
snapStop: false,
/**
* custom easing function
* [default: easeInOutQuad]
* custom easing function [default: easeInOutQuad]
* for reference: https://gist.github.com/gre/1650294
* @param t normalized time typically in the range [0, 1]
*/
Expand Down Expand Up @@ -99,7 +82,7 @@ cd scroll-snap
yarn install
```

Start the test app from `docs/`:
Start the testing environment from `playground/`:

```
yarn start
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Binary file removed docs/dist/assets/snippet-constructor-mobile.png
Binary file not shown.
Binary file removed docs/dist/assets/snippet-constructor.png
Binary file not shown.
Binary file removed docs/dist/assets/snippet-unbind-mobile.png
Binary file not shown.
Binary file removed docs/dist/assets/snippet-unbind.png
Binary file not shown.
1 change: 0 additions & 1 deletion docs/dist/scroll-snap.js

This file was deleted.

6 changes: 3 additions & 3 deletions docs/dist/index.html → docs/index.html
Expand Up @@ -2,15 +2,15 @@
<html>
<head>
<meta charset="utf-8" />
<title>scroll-snap - Customizable page snapping</title>
<title>scroll-snap - customizable page snapping</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div id="container">
<div class="page first-page">
<div class="logo"></div>
<div class="hint" style="position: absolute; bottom: 10%">
<div class="hint" style="position: absolute; bottom: 10%;">
<div class="scroll"></div>
</div>
</div>
Expand Down Expand Up @@ -100,6 +100,6 @@ <h2><span class="highlight">Complete control</span> over the scroll behaviour</h
</div>
</div>
</div>
<script src="scroll-snap.js"></script>
<script type="module" src="index.js"></script>
</body>
</html>
13 changes: 2 additions & 11 deletions docs/src/index.ts → docs/index.js
@@ -1,4 +1,4 @@
import ScrollSnap from '../../src/index'
import ScrollSnap from 'https://unpkg.com/scroll-snap/dist/esm/index.js'

function callback() {
console.log('snap')
Expand All @@ -8,7 +8,7 @@ const baseConfig = {
timeout: 100,
duration: 300,
threshold: 0.2,
easing: (t: number) => (t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t),
easing: (t) => (t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t),
}

const containerVertical = document.getElementById('container')
Expand All @@ -22,12 +22,3 @@ const snapHorizontal = new ScrollSnap(containerHorizontal, {
snapDestinationX: '100%',
...baseConfig,
}).bind(callback)

;(window as any).unbind = () => {
snapVertical.unbind()
snapHorizontal.unbind()
}
;(window as any).bind = () => {
snapVertical.bind(callback)
snapHorizontal.bind(callback)
}
11 changes: 0 additions & 11 deletions docs/src/assets/arrow-down.svg

This file was deleted.

19 changes: 0 additions & 19 deletions docs/src/assets/github.svg

This file was deleted.

90 changes: 0 additions & 90 deletions docs/src/assets/logo.svg

This file was deleted.

45 changes: 0 additions & 45 deletions docs/src/assets/scroll.svg

This file was deleted.

Binary file removed docs/src/assets/snippet-constructor-mobile.png
Binary file not shown.
Binary file removed docs/src/assets/snippet-constructor.png
Binary file not shown.
Binary file removed docs/src/assets/snippet-unbind-mobile.png
Binary file not shown.
Binary file removed docs/src/assets/snippet-unbind.png
Binary file not shown.

0 comments on commit 0a44e37

Please sign in to comment.