Skip to content

Commit 509703c

Browse files
resolvendo funcoes
1 parent d81fb7e commit 509703c

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/components/BackToTop/BackToTop.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,26 @@ import { useState } from "react"
22

33
const BackToTop =() => {
44

5-
const [isVisible, setVisibility] = useState(false)
5+
const [isVisible, setVisibility] = useState(!false)
66

77
const scrollToTop = () => {
8-
window.scrollTo({top:0, behavior:"smooth"})
8+
let root = document.getElementById('root')
9+
if (!root) {return}
910

10-
console.log(window.scrollY)
11+
root.scrollTo({top:0, behavior:"smooth"})
12+
1113
}
1214

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) {
1520
setVisibility(true)
1621
} else {
1722
setVisibility(false)
1823
}
1924
})
20-
//document.getElementById('root').addEventListener('scroll', (e) => console.log(e.target.scrollTop))
2125

2226

2327
return (isVisible && (

0 commit comments

Comments
 (0)