forked from BraydenTW/react-emoji-search
-
Notifications
You must be signed in to change notification settings - Fork 0
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
54729b6
commit 4dd56b3
Showing
5 changed files
with
4,590 additions
and
2,813 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
.scroll-to-top-wrapper { | ||
position: fixed; | ||
bottom: 1rem; | ||
right: 1rem; | ||
} | ||
|
||
.scroll-top-button { | ||
padding: 1rem; | ||
border-radius: 1rem; | ||
background-color: white; | ||
box-shadow: -5px -5px 15px #ffffff99, 5px 5px 15px #152b4711; | ||
display: flex; | ||
align-items: center; | ||
justify-items: center; | ||
cursor: pointer; | ||
animation: fadeIn 0.5s; | ||
} | ||
|
||
@keyframes fadeIn { | ||
0% { | ||
opacity: 0; | ||
} | ||
100% { | ||
opacity: 1; | ||
} | ||
} |
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,42 @@ | ||
import { useState, useEffect } from "react"; | ||
import "./ScrollToTopButton.css"; | ||
import { ReactComponent as UpIcon } from "../assets/up.svg"; | ||
|
||
const ScrollToTopButton = () => { | ||
const [showScrollToTop, setScrollToTop] = useState(false); | ||
|
||
const scrollToTop = () => { | ||
window.scrollTo({ | ||
top: 0, | ||
behavior: "smooth", | ||
}); | ||
}; | ||
|
||
useEffect(() => { | ||
const toggleVisibility = () => { | ||
if (window.pageYOffset > 500) { | ||
setScrollToTop(true); | ||
} else { | ||
setScrollToTop(false); | ||
} | ||
}; | ||
|
||
window.addEventListener("scroll", toggleVisibility); | ||
|
||
return () => window.removeEventListener("scroll", toggleVisibility); | ||
}, []); | ||
|
||
return ( | ||
<div className="scroll-to-top-wrapper"> | ||
{showScrollToTop && ( | ||
<div onClick={scrollToTop}> | ||
<div className="scroll-top-button"> | ||
<UpIcon /> | ||
</div> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default ScrollToTopButton; |
Oops, something went wrong.