File tree Expand file tree Collapse file tree 6 files changed +160
-41
lines changed Expand file tree Collapse file tree 6 files changed +160
-41
lines changed Original file line number Diff line number Diff line change 9
9
"react" : " ^17.0.2" ,
10
10
"react-dom" : " ^17.0.2" ,
11
11
"react-scripts" : " 4.0.3" ,
12
+ "smooth-scrollbar" : " ^8.6.3" ,
12
13
"web-vitals" : " ^1.1.2"
13
14
},
14
15
"scripts" : {
Original file line number Diff line number Diff line change
1
+
2
+
1
3
.App {
2
- text-align : center;
4
+
5
+
6
+ display : flex;
7
+ flex-direction : column;
8
+ padding : 5rem ;
3
9
}
4
10
5
- .App-logo {
6
- height : 40vmin ;
7
- pointer-events : none;
11
+ .title {
12
+ text-transform : uppercase;
13
+ align-self : center;
14
+ margin-bottom : 8rem ;
15
+ font-size : 4vw ;
8
16
}
9
17
10
- @media (prefers-reduced-motion : no-preference) {
11
- .App-logo {
12
- animation : App-logo-spin infinite 20s linear;
13
- }
18
+ .imgContainer {
19
+ max-width : 50vw ;
20
+ margin : 4rem 0 ;
14
21
}
15
22
16
- .App-header {
17
- background-color : # 282c34 ;
18
- min-height : 100vh ;
19
- display : flex;
20
- flex-direction : column;
21
- align-items : center;
22
- justify-content : center;
23
- font-size : calc (10px + 2vmin );
24
- color : white;
23
+ img {
24
+ width : 100% ;
25
+ height : auto;
26
+
25
27
}
26
28
27
- .App-link {
28
- color : # 61dafb ;
29
+
30
+ .scrollbar-track {
31
+ background-color : transparent !important ;
29
32
}
30
33
31
- @keyframes App-logo-spin {
32
- from {
33
- transform : rotate (0deg );
34
- }
35
- to {
36
- transform : rotate (360deg );
37
- }
34
+ .scrollbar-track-y {
35
+ width : 12px !important ;
38
36
}
37
+
38
+
39
+ .scrollbar-thumb {
40
+ width : 12px !important ;
41
+ background-color : black !important ;
42
+ border-radius : 0 !important ;
43
+ }
44
+
Original file line number Diff line number Diff line change 1
- import logo from './logo.svg' ;
1
+ import { useEffect , useState } from 'react' ;
2
+ import Scroll from './components/SmoothScroll' ;
3
+
2
4
import './App.css' ;
3
5
4
6
function App ( ) {
7
+ const [ images , setImages ] = useState ( ) ;
8
+
9
+
10
+
11
+ useEffect ( ( ) => {
12
+ fetch ( 'https://picsum.photos/v2/list?limit=10' ) . then ( res => res . json ( ) )
13
+ . then ( json => {
14
+ //console.log(json);
15
+ setImages ( json ) ;
16
+ } ) ;
17
+
18
+ } , [ ] )
19
+
20
+ const random = ( ) => {
21
+ return Math . floor ( Math . random ( ) * 50 ) ;
22
+ }
5
23
return (
6
24
< div className = "App" >
7
- < header className = "App-header" >
8
- < img src = { logo } className = "App-logo" alt = "logo" />
9
- < p >
10
- Edit < code > src/App.js</ code > and save to reload.
11
- </ p >
12
- < a
13
- className = "App-link"
14
- href = "https://reactjs.org"
15
- target = "_blank"
16
- rel = "noopener noreferrer"
17
- >
18
- Learn React
19
- </ a >
20
- </ header >
25
+ < h1 className = "title" > React Smooth Scroll</ h1 >
26
+ < Scroll />
27
+ {
28
+ images && images . map (
29
+ img => < div style = { { marginLeft :`${ random ( ) } rem` } } key = { img . id } className = "imgContainer" >
30
+ < img src = { img . download_url } alt = { img . author } />
31
+ </ div >
32
+ )
33
+ }
21
34
</ div >
22
35
) ;
23
36
}
Original file line number Diff line number Diff line change
1
+ import Scrollbar from 'smooth-scrollbar' ;
2
+ import { useEffect } from 'react' ;
3
+ import OverscrollPlugin from 'smooth-scrollbar/plugins/overscroll' ;
4
+
5
+
6
+
7
+
8
+ const overscrollOptions = {
9
+ enable : true ,
10
+ effect : 'bounce' ,
11
+ damping : 0.15 ,
12
+ maxOverscroll : 150 ,
13
+ glowColor : '#fff' ,
14
+ } ;
15
+
16
+ // const overscrollOptions = {
17
+ // enable: true,
18
+ // effect: 'glow',
19
+ // damping: 0.1,
20
+ // maxOverscroll: 200,
21
+ // glowColor: '#222a2d',
22
+ // };
23
+
24
+
25
+ const options = {
26
+ damping : 0.07 ,
27
+ thumbMinSize : 100 ,
28
+ plugins : {
29
+ overscroll : { ...overscrollOptions } ,
30
+ } ,
31
+
32
+ }
33
+
34
+ const Scroll = ( ) => {
35
+
36
+ useEffect ( ( ) => {
37
+
38
+ Scrollbar . use ( OverscrollPlugin ) ;
39
+
40
+ Scrollbar . init ( document . body , options ) ;
41
+
42
+
43
+
44
+
45
+ return ( ) => {
46
+ if ( Scrollbar ) Scrollbar . destroy ( document . body )
47
+ } } , [ ] )
48
+
49
+
50
+
51
+ return null ;
52
+ }
53
+
54
+ export default Scroll ;
Original file line number Diff line number Diff line change 5
5
sans-serif;
6
6
-webkit-font-smoothing : antialiased;
7
7
-moz-osx-font-smoothing : grayscale;
8
+ height : 100vh ;
9
+ width : 100vw ;
8
10
}
9
11
10
12
code {
You can’t perform that action at this time.
0 commit comments