-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #454 from RadhikaMalpani1702/master
Added Scroll-to-Top Button #444
- Loading branch information
Showing
7 changed files
with
64 additions
and
10 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -59,4 +59,4 @@ | |
"eslint": "^8.57.0", | ||
"eslint-plugin-react": "^7.34.3" | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
} | ||
.scrolltop{ | ||
size: 20px; | ||
|
||
} | ||
.footer-container { | ||
display: flex; | ||
|
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,57 @@ | ||
import React, { useState, useEffect } from "react"; | ||
import styled from "styled-components"; | ||
import { FaArrowUp } from "react-icons/fa"; | ||
|
||
const GoToTop = () => { | ||
const [isVisible, setIsVisible] = useState(false); | ||
|
||
useEffect(() => { | ||
const handleScroll = () => { | ||
const currentScrollY = window.scrollY; | ||
|
||
setIsVisible(currentScrollY > 200); // Change 200 to your desired scroll distance | ||
}; | ||
|
||
window.addEventListener("scroll", handleScroll); | ||
|
||
return () => { | ||
window.removeEventListener("scroll", handleScroll); | ||
}; | ||
}, []); | ||
|
||
const goToTop = () => { | ||
window.scrollTo({ top: 0, left: 0, behavior: "smooth" }); | ||
}; | ||
|
||
return ( | ||
<> | ||
{isVisible && ( | ||
<Wrapper onClick={goToTop}> | ||
<FaArrowUp className="top-btn--icon" /> | ||
</Wrapper> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
const Wrapper = styled.div` | ||
z-index: 9999; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
position: fixed; | ||
bottom: 25px; | ||
left: 40px; | ||
color: white; | ||
background-color: #ff21bc; | ||
width: 50px; | ||
height: 50px; | ||
border-radius: 50%; | ||
cursor: pointer; | ||
&:hover { | ||
background-color: darkturquoise; | ||
} | ||
`; | ||
|
||
export default GoToTop; |
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