1- import React , { useState , useRef } from ' react' ;
2- import useSmoothScroll from ' react-smooth-scroll-hook' ;
1+ import React , { useState , useRef } from " react" ;
2+ import useSmoothScroll from " react-smooth-scroll-hook" ;
33
44export const DirectionX = ( ) => {
5- const [ speed , setSpeed ] = useState ( 50 ) ;
5+ const [ speed , setSpeed ] = useState ( 200 ) ;
66 const ref = useRef < HTMLDivElement > ( null ) ;
77 const { scrollTo, reachTop, reachBottom, scrollToPage } = useSmoothScroll ( {
88 ref,
9- direction : 'x' ,
10- speed,
9+ direction : "x" ,
10+ speed
1111 } ) ;
1212 const onChange = ( evt : React . ChangeEvent < HTMLInputElement > ) => {
1313 setSpeed ( Number ( evt . target . value ) ) ;
1414 } ;
1515 return (
1616 < >
17- < button onClick = { ( ) => scrollTo ( '#x-item-20' ) } >
18- scrollTo('#x-item-20')
19- </ button >
20- < button onClick = { ( ) => scrollTo ( Infinity ) } >
21- scrollTo Edge - scrollTo(Infinity)
22- </ button >
23- < button onClick = { ( ) => scrollTo ( - Infinity ) } >
24- scrollTo Edge - scrollTo(-Infinity)
25- </ button >
26- < button onClick = { ( ) => scrollTo ( 100 ) } > scrollTo(100)</ button >
27- < button onClick = { ( ) => scrollTo ( - 100 ) } > scrollTo(-100)</ button >
28-
29- < br />
3017 < div >
31- speed:{ speed }
18+ < strong > speed:{ speed } </ strong >
3219 < br />
3320 < input
3421 value = { speed }
@@ -37,29 +24,52 @@ export const DirectionX = () => {
3724 min = { 100 }
3825 max = { 500 }
3926 />
40- < br />
41- reachTop: { String ( reachTop ) }
42- < br />
43- reachBottom: { String ( reachBottom ) }
4427 </ div >
4528 < br />
46- < button disabled = { reachBottom } onClick = { ( ) => scrollToPage ( 1 ) } >
47- scrollToPage(1)
48- </ button >
49- < button disabled = { reachTop } onClick = { ( ) => scrollToPage ( - 1 ) } >
50- scrollToPage(-1)
51- </ button >
52-
29+ < strong >
30+ Pass string:
31+ < button onClick = { ( ) => scrollTo ( "#x-item-20" ) } >
32+ scrollTo('#x-item-20')
33+ </ button >
34+ </ strong >
35+ < br />
36+ < strong >
37+ Pass number:
38+ < button onClick = { ( ) => scrollTo ( 100 ) } > scrollTo(100)</ button >
39+ < button onClick = { ( ) => scrollTo ( - 100 ) } > scrollTo(-100)</ button >
40+ </ strong >
41+ < br />
42+ < strong >
43+ Scroll to Edge:
44+ < button onClick = { ( ) => scrollTo ( Infinity ) } > scrollTo Bottom</ button >
45+ < button onClick = { ( ) => scrollTo ( - Infinity ) } > scrollTo Top</ button >
46+ </ strong >
47+ < br />
48+ < strong >
49+ Scroll to Page:
50+ < button disabled = { reachBottom } onClick = { ( ) => scrollToPage ( 1 ) } >
51+ scrollToPage(1)
52+ </ button >
53+ < button disabled = { reachTop } onClick = { ( ) => scrollToPage ( - 1 ) } >
54+ scrollToPage(-1)
55+ </ button >
56+ </ strong >
57+ < br />
58+ < br />
59+ reachTop: { String ( reachTop ) }
60+ < br />
61+ reachBottom: { String ( reachBottom ) }
62+ < br />
5363 < div
5464 ref = { ref }
5565 style = { {
56- overflowX : ' scroll' ,
66+ overflowX : " scroll"
5767 } }
5868 >
5969 < div
6070 style = { {
61- display : ' flex' ,
62- padding : ' 10px' ,
71+ display : " flex" ,
72+ padding : " 10px"
6373 } }
6474 >
6575 { Array ( 50 )
@@ -70,7 +80,7 @@ export const DirectionX = () => {
7080 id = { `x-item-${ i } ` }
7181 style = { {
7282 flexShrink : 0 ,
73- padding : ' 10px' ,
83+ padding : " 10px"
7484 } }
7585 >
7686 x-item-{ i }
0 commit comments