-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
97a23b1
commit 70f3f4b
Showing
6 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { useState, useEffect } from "react"; | ||
|
||
export const ScrollToTop = () => { | ||
const [showButton, setShowButton] = useState(false); | ||
const toggleButton = () => setShowButton(window.scrollY > 100); | ||
const scrollToTop = () => window.scrollTo({ top: 0, behavior: "smooth" }); | ||
|
||
useEffect(() => { | ||
document.addEventListener("scroll", toggleButton); | ||
return () => { | ||
document.removeEventListener("scroll", toggleButton); | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<button | ||
onClick={scrollToTop} | ||
className={`fixed bg-purple-500 hover:bg-purple-600 duration-300 w-10 h-10 rounded-full bottom-16 right-3 flex justify-center items-center ${ | ||
showButton || "hidden" | ||
}`} | ||
> | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
viewBox="0 0 384 512" | ||
className="w-4 h-4" | ||
fill="white" | ||
> | ||
<path d="M214.6 41.4c-12.5-12.5-32.8-12.5-45.3 0l-160 160c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0L160 141.2V448c0 17.7 14.3 32 32 32s32-14.3 32-32V141.2L329.4 246.6c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3l-160-160z" /> | ||
</svg> | ||
</button> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters