Skip to content

Commit 458788d

Browse files
Adicionado funcoes para o botao. COMENTADO OVERFLOW-X:HIDDEN no global.css
1 parent 11d59fd commit 458788d

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

src/components/BackToTop/BackToTop.tsx

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,27 @@ import { useState } from "react"
22

33
const BackToTop =() => {
44

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

77
const scrollToTop = () => {
8-
window.scrollTo(0,0)
8+
window.scrollTo({top:0, behavior:"smooth"})
99

10-
console.log("click!")
10+
console.log(window.scrollY)
1111
}
1212

13-
const toggleVisibility = () => {
14-
if (window.scrollY >= window.innerHeight) {
13+
window.addEventListener("scroll", () => {
14+
if ( window.innerHeight / 2 < window.scrollY) {
1515
setVisibility(true)
1616
} else {
1717
setVisibility(false)
1818
}
19-
20-
console.log("scrooled")
21-
}
19+
})
2220

2321

2422
return (isVisible && (
2523
<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}
3126
>^</button>
3227
));
3328
}

src/global.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,6 @@
8888

8989
#root {
9090
max-width: 100vw;
91-
overflow-x: hidden;
91+
/*overflow-x: hidden;*/
9292
}
9393
}

0 commit comments

Comments
 (0)