File tree Expand file tree Collapse file tree 1 file changed +10
-6
lines changed Expand file tree Collapse file tree 1 file changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -2,22 +2,26 @@ import { useState } from "react"
2
2
3
3
const BackToTop = ( ) => {
4
4
5
- const [ isVisible , setVisibility ] = useState ( false )
5
+ const [ isVisible , setVisibility ] = useState ( ! false )
6
6
7
7
const scrollToTop = ( ) => {
8
- window . scrollTo ( { top :0 , behavior :"smooth" } )
8
+ let root = document . getElementById ( 'root' )
9
+ if ( ! root ) { return }
9
10
10
- console . log ( window . scrollY )
11
+ root . scrollTo ( { top :0 , behavior :"smooth" } )
12
+
11
13
}
12
14
13
- window . addEventListener ( "scroll" , ( ) => {
14
- if ( window . innerHeight / 2 < window . scrollY ) {
15
+ document . getElementById ( "root" ) ?. addEventListener ( 'scroll' , ( e ) => {
16
+ let CurrentScrollHeight = e . target . scrollTop
17
+ let WindowHeight = window . innerHeight
18
+
19
+ if ( CurrentScrollHeight > WindowHeight / 2 ) {
15
20
setVisibility ( true )
16
21
} else {
17
22
setVisibility ( false )
18
23
}
19
24
} )
20
- //document.getElementById('root').addEventListener('scroll', (e) => console.log(e.target.scrollTop))
21
25
22
26
23
27
return ( isVisible && (
You can’t perform that action at this time.
0 commit comments