forked from code100x/job-board
-
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.
added scroll-top feature and navbar feature (code100x#297)
- Loading branch information
Showing
4 changed files
with
71 additions
and
1 deletion.
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
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,41 @@ | ||
'use client'; | ||
import { Button } from './ui/button'; | ||
import { MoveUp } from 'lucide-react'; | ||
import { useEffect, useState } from 'react'; | ||
|
||
export default function ScrollToTop() { | ||
const [isVisible, setIsVisible] = useState(false); | ||
|
||
useEffect(() => { | ||
const handleScroll = () => { | ||
if (window.scrollY > 200) { | ||
setIsVisible(true); | ||
} else { | ||
setIsVisible(false); | ||
} | ||
}; | ||
window.addEventListener('scroll', handleScroll); | ||
|
||
return () => { | ||
window.removeEventListener('scroll', handleScroll); | ||
}; | ||
}, []); | ||
|
||
function toUp() { | ||
window.scrollTo({ | ||
top: 0, | ||
behavior: 'smooth', | ||
}); | ||
} | ||
return ( | ||
<Button | ||
className={`fixed bottom-5 right-5 w-[50px] h-[50px] rounded-full bg-white text-black flex items-center justify-center shadow-lg hover:bg-gray-200 transition-opacity duration-300 ${ | ||
isVisible ? 'opacity-100' : 'opacity-0 pointer-events-none' | ||
}`} | ||
aria-label="Scroll to top" | ||
onClick={toUp} | ||
> | ||
<MoveUp className="text-black" /> | ||
</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