File tree Expand file tree Collapse file tree 2 files changed +9
-14
lines changed Expand file tree Collapse file tree 2 files changed +9
-14
lines changed Original file line number Diff line number Diff line change @@ -2,32 +2,27 @@ import { useState } from "react"
2
2
3
3
const BackToTop = ( ) => {
4
4
5
- const [ isVisible , setVisibility ] = useState ( true )
5
+ const [ isVisible , setVisibility ] = useState ( false )
6
6
7
7
const scrollToTop = ( ) => {
8
- window . scrollTo ( 0 , 0 )
8
+ window . scrollTo ( { top : 0 , behavior : "smooth" } )
9
9
10
- console . log ( "click!" )
10
+ console . log ( window . scrollY )
11
11
}
12
12
13
- const toggleVisibility = ( ) => {
14
- if ( window . scrollY >= window . innerHeight ) {
13
+ window . addEventListener ( "scroll" , ( ) => {
14
+ if ( window . innerHeight / 2 < window . scrollY ) {
15
15
setVisibility ( true )
16
16
} else {
17
17
setVisibility ( false )
18
18
}
19
-
20
- console . log ( "scrooled" )
21
- }
19
+ } )
22
20
23
21
24
22
return ( isVisible && (
25
23
< button
26
- className = " absolute bg-red-800/60 z-[100] right-10 bottom-10 w-12 h-12 rounded-full shadow-slate-500 font-bold shadow-md text-white select-none"
27
- onClick = { scrollToTop }
28
- onScroll = { toggleVisibility }
29
-
30
-
24
+ className = " fixed ease-in-out duration-300 hover:bg-red-800/100 bg-red-800/40 z-[100] right-10 bottom-10 w-12 h-12 rounded-full shadow-slate-500 font-bold shadow-md text-white select-none"
25
+ onClick = { scrollToTop }
31
26
> ^</ button >
32
27
) ) ;
33
28
}
Original file line number Diff line number Diff line change 88
88
89
89
# root {
90
90
max-width : 100vw ;
91
- overflow-x : hidden;
91
+ /* overflow-x: hidden;*/
92
92
}
93
93
}
You can’t perform that action at this time.
0 commit comments