-
Notifications
You must be signed in to change notification settings - Fork 8
/
App.tsx
59 lines (55 loc) · 1.75 KB
/
App.tsx
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
import React, { useRef } from 'react';
import './App.css';
import { useConveyer } from './react-conveyer/useConveyer';
function App() {
const ref = useRef<HTMLElement>(null) as any as ((e: HTMLElement | null) => void) & { current: HTMLElement | null };
const {
isReachStart,
isReachEnd,
scrollIntoView,
onBeginScroll,
onFinishScroll,
} = useConveyer(ref, {
preventClickOnDrag: true,
horizontal: false,
});
onBeginScroll(() => {
console.log("begin scroll");
}, []);
onFinishScroll(() => {
console.log("finish scroll");
}, []);
return (
<div className="App">
<button id="prev" disabled={isReachStart} onClick={() => {
// start to end
scrollIntoView("start", {
align: "end",
duration: 500,
});
}}>PREV</button>
<button id="next" disabled={isReachEnd} onClick={() => {
// end to start
scrollIntoView("end", {
align: "start",
duration: 500,
});
}}>NEXT</button>
<div className="items" ref={ref}>
<div className="item"><a href="#1">1</a></div>
<div className="item"><a href="#2">2</a></div>
<div className="item"><a href="#3">3</a></div>
<div className="item"><a href="#4">4</a></div>
<div className="item"><a href="#5">5</a></div>
<div className="item"><a href="#6">6</a></div>
<div className="item"><a href="#7">7</a></div>
<div className="item"><a href="#8">8</a></div>
<div className="item"><a href="#9">9</a></div>
<div className="item"><a href="#10">10</a></div>
<div className="item"><a href="#11">11</a></div>
<div className="item"><a href="#12">12</a></div>
</div>
</div>
);
}
export default App;