-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
SlickGoTo.js
51 lines (49 loc) · 1.24 KB
/
SlickGoTo.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
import React, { useState, useRef } from "react";
import Slider from "react-slick";
import { baseUrl } from "./config";
function SlickGoTo() {
const [slideIndex, setSlideIndex] = useState(0);
const [updateCount, setUpdateCount] = useState(0);
let sliderRef = useRef(null);
const settings = {
dots: false,
infinite: true,
speed: 500,
slidesToShow: 1,
slidesToScroll: 1,
afterChange: () => setUpdateCount(updateCount + 1),
beforeChange: (current, next) => setSlideIndex(next)
};
return (
<div className="slider-container">
<p>Total updates: {updateCount} </p>
<input
onChange={e => sliderRef.slickGoTo(e.target.value)}
value={slideIndex}
type="range"
min={0}
max={3}
/>
<Slider
ref={slider => {
sliderRef = slider;
}}
{...settings}
>
<div>
<img src={baseUrl + "/abstract01.jpg"} />
</div>
<div>
<img src={baseUrl + "/abstract02.jpg"} />
</div>
<div>
<img src={baseUrl + "/abstract03.jpg"} />
</div>
<div>
<img src={baseUrl + "/abstract04.jpg"} />
</div>
</Slider>
</div>
);
}
export default SlickGoTo;