-
Notifications
You must be signed in to change notification settings - Fork 256
/
index.js
64 lines (57 loc) · 1.76 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import querystring from 'querystring';
import ReactSwipe from '../src';
const query = querystring.parse(window.location.search.slice(1));
// generate slide panes
const numberOfSlides = parseInt(query.slidesNum, 10) || 20;
const paneNodes = Array.apply(null, Array(numberOfSlides)).map((_, i) => {
return (
<div key={i}>
<div className="item">{i}</div>
</div>
);
});
// change Swipe.js options by query params
const startSlide = parseInt(query.startSlide, 10) || 0;
const swipeOptions = {
startSlide: startSlide < paneNodes.length && startSlide >= 0 ? startSlide : 0,
auto: parseInt(query.auto, 10) || 0,
speed: parseInt(query.speed, 10) || 300,
disableScroll: query.disableScroll === 'true',
continuous: query.continuous === 'true',
widthOfSiblingSlidePreview:
parseInt(query.widthOfSiblingSlidePreview, 10) || 0,
callback() {
console.log('slide changed');
},
transitionEnd() {
console.log('ended transition');
}
};
const Page = () => {
let reactSwipeEl;
return (
<div className="center">
<h1>ReactSwipe.js</h1>
<h2>Open this page from a mobile device (real or emulated).</h2>
<h2>
You can pass{' '}
<a href="https://github.com/voronianski/swipe-js-iso#config-options">
Swipe.js options
</a>{' '}
as query params.
</h2>
<ReactSwipe
className="mySwipe"
swipeOptions={swipeOptions}
ref={el => (reactSwipeEl = el)}
>
{paneNodes}
</ReactSwipe>
<button onClick={() => reactSwipeEl.prev()}>Prev</button>
<button onClick={() => reactSwipeEl.next()}>Next</button>
</div>
);
};
ReactDOM.render(<Page />, document.getElementById('app'));