-
Notifications
You must be signed in to change notification settings - Fork 6
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
Harsh Vardhan Gupta
committed
Jan 23, 2024
1 parent
285b349
commit c7ffb6b
Showing
5 changed files
with
134 additions
and
19 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,27 @@ | ||
.go-up-arrow { | ||
position: fixed; | ||
bottom: 20px; | ||
right: 20px; | ||
background-color: #007bff; | ||
color: #fff; | ||
border: none; | ||
padding: 10px; | ||
border-radius: 50%; | ||
cursor: pointer; | ||
font-size: 1.5em; | ||
transition: opacity 0.3s ease-in-out; | ||
height: 3rem; | ||
width: 3rem; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
} | ||
|
||
.go-up-arrow.hidden { | ||
opacity: 0; | ||
pointer-events: none; /* Disable clicking when hidden */ | ||
} | ||
|
||
.go-up-arrow:hover { | ||
opacity: 0.8; | ||
} |
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,39 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import './GoUpArrow.css'; // Import your CSS file | ||
|
||
const GoUpArrow = () => { | ||
const [isVisible, setIsVisible] = useState(false); | ||
|
||
useEffect(() => { | ||
// Show the "Go Up" arrow when scrolling down | ||
const handleScroll = () => { | ||
if (window.scrollY > 100) { | ||
setIsVisible(true); | ||
} else { | ||
setIsVisible(false); | ||
} | ||
}; | ||
|
||
window.addEventListener('scroll', handleScroll); | ||
|
||
// Clean up the event listener when the component unmounts | ||
return () => { | ||
window.removeEventListener('scroll', handleScroll); | ||
}; | ||
}, []); | ||
|
||
const scrollToTop = () => { | ||
window.scrollTo({ top: 0, behavior: 'smooth' }); | ||
}; | ||
|
||
return ( | ||
<div | ||
className={`go-up-arrow ${isVisible ? 'visible' : 'hidden'}`} | ||
onClick={scrollToTop} | ||
> | ||
<i class="fa-solid fa-arrow-up"></i> | ||
</div> | ||
); | ||
}; | ||
|
||
export default GoUpArrow; |
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